Skip to content

Commit d7a8939

Browse files
authored
Merge pull request #329 from internxt/bugfix/PB-5454-log-log-out
[PB-5454] feature/Add logs when logout thunk is called
2 parents 9ecae15 + f0d8d86 commit d7a8939

5 files changed

Lines changed: 26 additions & 23 deletions

File tree

src/components/modals/SignOutModal/index.tsx

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,16 @@
1-
import React from 'react';
21
import { View } from 'react-native';
32

3+
import { useNavigation } from '@react-navigation/native';
4+
import { useTailwind } from 'tailwind-rn';
45
import strings from '../../../../assets/lang/strings';
56
import { useAppDispatch, useAppSelector } from '../../../store/hooks';
7+
import { authSelectors, authThunks } from '../../../store/slices/auth';
68
import { uiActions } from '../../../store/slices/ui';
7-
import CenterModal from '../CenterModal';
9+
import { RootScreenNavigationProp } from '../../../types/navigation';
810
import AppButton from '../../AppButton';
911
import AppText from '../../AppText';
10-
import { authSelectors, authThunks } from '../../../store/slices/auth';
11-
import { useNavigation } from '@react-navigation/native';
12-
import { RootScreenNavigationProp } from '../../../types/navigation';
13-
import { useTailwind } from 'tailwind-rn';
1412
import UserProfilePicture from '../../UserProfilePicture';
13+
import CenterModal from '../CenterModal';
1514

1615
function SignOutModal(): JSX.Element {
1716
const tailwind = useTailwind();
@@ -27,7 +26,7 @@ function SignOutModal(): JSX.Element {
2726
onClosed();
2827
};
2928
const onSignOutButtonPressed = () => {
30-
dispatch(authThunks.signOutThunk());
29+
dispatch(authThunks.signOutThunk({ reason: 'manual' }));
3130
navigation.replace('SignIn');
3231
onClosed();
3332
};

src/navigation/TabExplorerNavigator.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ export default function TabExplorerNavigator(props: RootStackScreenProps<'TabExp
5454
} catch {
5555
const isDeletingAccount = await asyncStorageService.getItem(AsyncStorageKey.IsDeletingAccount);
5656
if (isDeletingAccount) {
57-
dispatch(authThunks.signOutThunk());
57+
dispatch(authThunks.signOutThunk({ reason: 'manual' }));
5858
props.navigation.replace('DeactivatedAccount');
5959
}
6060
}

src/plugins/AxiosPlugin.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ const axiosPlugin: AppPlugin = {
88
axios.interceptors.response.use(undefined, (err) => {
99
if (err.response) {
1010
if (err.response.status === 401) {
11-
store.dispatch(authThunks.signOutThunk());
11+
store.dispatch(authThunks.signOutThunk({ reason: 'unauthorized' }));
1212
}
1313
}
1414

src/services/AuthService.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { logger } from '@internxt-mobile/services/common';
12
import { internxtMobileSDKConfig } from '@internxt/mobile-sdk';
23
import { Keys, Password, TwoFactorAuthQR } from '@internxt/sdk';
34
import { StorageTypes } from '@internxt/sdk/dist/drive';
@@ -154,7 +155,8 @@ class AuthService {
154155
}
155156
}
156157

157-
public async signout(): Promise<void> {
158+
public async signout(reason: 'manual' | 'unauthorized' | 'token_expired'): Promise<void> {
159+
logger.info(`User logged out - Reason: ${reason}`);
158160
analytics.track(AnalyticsEventKey.UserLogout);
159161
await asyncStorageService.clearStorage();
160162
await internxtMobileSDKConfig.destroy();

src/store/slices/auth/index.ts

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ export const refreshTokensThunk = createAsyncThunk<void, void, { state: RootStat
173173
logger.info('Auth tokens refresh failed: ', JSON.stringify(err));
174174
asyncStorageService.clearStorage();
175175
dispatch(authActions.setLoggedIn(false));
176-
dispatch(authThunks.signOutThunk());
176+
dispatch(authThunks.signOutThunk({ reason: 'token_expired' }));
177177
}
178178
},
179179
);
@@ -197,18 +197,20 @@ export const checkAndRefreshTokenThunk = createAsyncThunk<void, void, { state: R
197197
},
198198
);
199199

200-
export const signOutThunk = createAsyncThunk<void, void, { state: RootState }>(
201-
'auth/signOut',
202-
async (_, { dispatch }) => {
203-
authService.signout().catch(errorService.reportError);
204-
drive.clear().catch(errorService.reportError);
205-
dispatch(uiActions.resetState());
206-
dispatch(authActions.resetState());
207-
dispatch(driveActions.resetState());
208-
dispatch(authActions.setLoggedIn(false));
209-
authService.emitLogoutEvent();
210-
},
211-
);
200+
export const signOutThunk = createAsyncThunk<
201+
void,
202+
{ reason: 'manual' | 'unauthorized' | 'token_expired' },
203+
{ state: RootState }
204+
>('auth/signOut', async (payload, { dispatch }) => {
205+
const reason = payload.reason;
206+
authService.signout(reason).catch(errorService.reportError);
207+
drive.clear().catch(errorService.reportError);
208+
dispatch(uiActions.resetState());
209+
dispatch(authActions.resetState());
210+
dispatch(driveActions.resetState());
211+
dispatch(authActions.setLoggedIn(false));
212+
authService.emitLogoutEvent();
213+
});
212214

213215
export const refreshUserThunk = createAsyncThunk<void, void, { state: RootState }>(
214216
'auth/refreshUser',

0 commit comments

Comments
 (0)