complated project
This commit is contained in:
@@ -21,6 +21,7 @@ import {
|
||||
import { KeyboardAwareScrollView } from 'react-native-keyboard-aware-scroll-view';
|
||||
import { SafeAreaView } from 'react-native-safe-area-context';
|
||||
import { auth_api } from '../login/lib/api';
|
||||
import useTokenStore from '../login/lib/hook';
|
||||
import ConfirmForm from './ConfirmForm';
|
||||
|
||||
const ConfirmScreen = () => {
|
||||
@@ -28,6 +29,7 @@ const ConfirmScreen = () => {
|
||||
const [phoneOTP, setPhone] = useState<string | null>('');
|
||||
const [error, setError] = useState<string>('');
|
||||
const { login } = useAuth();
|
||||
const { savedToken } = useTokenStore();
|
||||
|
||||
const [resendTimer, setResendTimer] = useState<number>(60);
|
||||
|
||||
@@ -59,6 +61,7 @@ const ConfirmScreen = () => {
|
||||
onSuccess: async (res) => {
|
||||
await AsyncStorage.removeItem('phone');
|
||||
await AsyncStorage.setItem('access_token', res.data.data.token.access);
|
||||
savedToken(res.data.data.token.access);
|
||||
await login(res.data.data.token.access);
|
||||
await AsyncStorage.setItem('refresh_token', res.data.data.token.refresh);
|
||||
router.replace('/(dashboard)');
|
||||
|
||||
16
screens/auth/login/lib/hook.ts
Normal file
16
screens/auth/login/lib/hook.ts
Normal file
@@ -0,0 +1,16 @@
|
||||
import { create } from 'zustand';
|
||||
|
||||
type State = {
|
||||
token: string | null;
|
||||
};
|
||||
|
||||
type Actions = {
|
||||
savedToken: (token: string | null) => void;
|
||||
};
|
||||
|
||||
const useTokenStore = create<State & Actions>((set) => ({
|
||||
token: null,
|
||||
savedToken: (token: string | null) => set(() => ({ token })),
|
||||
}));
|
||||
|
||||
export default useTokenStore;
|
||||
@@ -21,6 +21,7 @@ import {
|
||||
import { KeyboardAwareScrollView } from 'react-native-keyboard-aware-scroll-view';
|
||||
import { SafeAreaView } from 'react-native-safe-area-context';
|
||||
import { auth_api } from '../login/lib/api';
|
||||
import useTokenStore from '../login/lib/hook';
|
||||
import ConfirmForm from './ConfirmForm';
|
||||
|
||||
const RegisterConfirmScreen = () => {
|
||||
@@ -28,6 +29,7 @@ const RegisterConfirmScreen = () => {
|
||||
const [phoneOTP, setPhone] = useState<string | null>('');
|
||||
const [error, setError] = useState<string>('');
|
||||
const { login } = useAuth();
|
||||
const { savedToken } = useTokenStore();
|
||||
|
||||
const [resendTimer, setResendTimer] = useState<number>(60);
|
||||
|
||||
@@ -59,6 +61,7 @@ const RegisterConfirmScreen = () => {
|
||||
onSuccess: async (res) => {
|
||||
await AsyncStorage.removeItem('phone');
|
||||
await AsyncStorage.setItem('access_token', res.data.data.token.access);
|
||||
savedToken(res.data.data.token.access);
|
||||
await AsyncStorage.setItem('refresh_token', res.data.data.token.refresh);
|
||||
await login(res.data.data.token.access);
|
||||
router.replace('/(dashboard)');
|
||||
|
||||
Reference in New Issue
Block a user