Skip to content

Commit 8795631

Browse files
committed
fix: auth
1 parent c0cef2d commit 8795631

File tree

4 files changed

+14
-3
lines changed

4 files changed

+14
-3
lines changed

app/(app)/(tabs)/_layout.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import { isNewUser } from '@/utils/user.utils';
1010
const _layout = () => {
1111
const { styles } = useStyles(stylesheet);
1212
const { data: user } = useUserProfile();
13+
1314
if (isNewUser(user)) {
1415
return <Redirect href="/(app)/(challenge)/creation" />;
1516
}

app/(auth)/_layout.tsx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
1-
import { Stack } from 'expo-router';
1+
import { Redirect, Stack } from 'expo-router';
22
import React from 'react';
33

4+
import { useUser } from '@/data/state/user.store';
5+
46
const _layout = () => {
7+
const { isAuthenticated } = useUser();
8+
if (isAuthenticated) return <Redirect href="/(app)" />;
59
return (
610
<Stack screenOptions={{ headerShown: false }}>
711
<Stack.Screen name="index" />

data/fetchers/auth.fetcher.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
import { useMutation, useQuery } from '@tanstack/react-query';
22

3+
import { queryClient } from '@/config/query.config';
4+
35
import { getUserProfile, googleAuth, refreshToken } from '../api/auth.api';
46
import { useUser } from '../state/user.store';
57

@@ -10,6 +12,7 @@ export const useAuthWithGoogle = () => {
1012
onSuccess: (data) => {
1113
if (data) {
1214
setToken(data.token);
15+
queryClient.invalidateQueries({ queryKey: ['user-profile'] });
1316
//router.replace('/(app)');
1417
}
1518
},

data/state/user.store.tsx

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { router } from 'expo-router';
1+
import { GoogleSignin } from '@react-native-google-signin/google-signin';
22
import { Alert, Linking } from 'react-native';
33
import type { StateCreator } from 'zustand';
44
import { create } from 'zustand';
@@ -7,6 +7,7 @@ import { immer } from 'zustand/middleware/immer';
77

88
import { Analytics } from '@/analytics';
99
import { Prefix } from '@/analytics/events';
10+
import { queryClient } from '@/config/query.config';
1011
import { DELETE_ACCOUNT_URL } from '@/constants/url.constants';
1112
import { asyncStoragePersistConfig } from '@/utils/storage.utils';
1213

@@ -35,6 +36,7 @@ const storeApi: StateCreator<UserStore, [['zustand/immer', never]]> = (
3536
// Methods
3637
setToken: (token) => {
3738
set((state) => {
39+
GoogleSignin.signOut();
3840
state.token = token;
3941
state.isAuthenticated = true;
4042
});
@@ -43,6 +45,7 @@ const storeApi: StateCreator<UserStore, [['zustand/immer', never]]> = (
4345
set(() => initialState);
4446
},
4547
logout: () => {
48+
GoogleSignin.signOut();
4649
useUserStore.getState().resetState();
4750
},
4851
});
@@ -65,9 +68,9 @@ export const useUser = () => {
6568
const logoutState = useUserStore((state) => state.logout);
6669

6770
const logout = () => {
71+
queryClient.removeQueries({ queryKey: ['user-profile'] });
6872
Analytics.trackEvent(Prefix.System.default + 'logout');
6973
Analytics.reset();
70-
router.replace('/(auth)');
7174
logoutState();
7275
};
7376

0 commit comments

Comments
 (0)