From e8d862e5e6dd8a6a517a93c65e30795813af936d Mon Sep 17 00:00:00 2001 From: ankit-thanekar007 Date: Mon, 29 Mar 2021 13:39:22 -0700 Subject: Logout changes --- src/screens/profile/SettingsScreen.tsx | 14 ++++++++++++-- src/store/actions/user.ts | 2 +- src/utils/users.ts | 2 +- 3 files changed, 14 insertions(+), 4 deletions(-) (limited to 'src') diff --git a/src/screens/profile/SettingsScreen.tsx b/src/screens/profile/SettingsScreen.tsx index 88962f71..05e051b5 100644 --- a/src/screens/profile/SettingsScreen.tsx +++ b/src/screens/profile/SettingsScreen.tsx @@ -8,15 +8,19 @@ import { TouchableOpacity, View, } from 'react-native'; -import {useSelector} from 'react-redux'; +import {useDispatch, useSelector} from 'react-redux'; +import {logout} from '../../store/actions'; import {RootState} from 'src/store/rootReducer'; import {Background} from '../../components'; import {SETTINGS_DATA} from '../../constants/constants'; import {BackgroundGradientType} from '../../types'; import {normalize, SCREEN_HEIGHT} from '../../utils/layouts'; import SettingsCell from './SettingsCell'; +import {useNavigation} from '@react-navigation/core'; const SettingsScreen: React.FC = () => { + const dispatch = useDispatch(); + const navigation = useNavigation(); const {suggested_people_linked} = useSelector( (state: RootState) => state.user.profile, ); @@ -44,7 +48,13 @@ const SettingsScreen: React.FC = () => { ListFooterComponent={() => ( {}}> + onPress={() => { + dispatch(logout()); + navigation.reset({ + index: 0, + routes: [{name: 'SuggestedPeople'}], + }); + }}> Logout )} diff --git a/src/store/actions/user.ts b/src/store/actions/user.ts index cb5e3dc1..374154da 100644 --- a/src/store/actions/user.ts +++ b/src/store/actions/user.ts @@ -158,7 +158,7 @@ export const logout = (): ThunkAction< Action > => async (dispatch) => { try { - AsyncStorage.clear(); + await AsyncStorage.clear(); dispatch({type: userLoggedIn.type, payload: {userId: '', username: ''}}); } catch (error) { console.log(error); diff --git a/src/utils/users.ts b/src/utils/users.ts index f9d6d6b7..22c1c1f0 100644 --- a/src/utils/users.ts +++ b/src/utils/users.ts @@ -133,7 +133,7 @@ export const loadAllSocialsForUser = async (userId: string, token?: string) => { export const getTokenOrLogout = async (dispatch: Function): Promise => { const token = await AsyncStorage.getItem('token'); if (!token) { - dispatch({type: userLoggedIn.type, payload: {userId: '', username: ''}}); + dispatch(logout()); return ''; } return token; -- cgit v1.2.3-70-g09d2