diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/screens/profile/SettingsScreen.tsx | 14 | ||||
-rw-r--r-- | src/store/actions/user.ts | 2 | ||||
-rw-r--r-- | src/utils/users.ts | 2 |
3 files changed, 14 insertions, 4 deletions
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={() => ( <TouchableOpacity style={styles.logoutContainerStyles} - onPress={() => {}}> + onPress={() => { + dispatch(logout()); + navigation.reset({ + index: 0, + routes: [{name: 'SuggestedPeople'}], + }); + }}> <Text style={styles.logoutTextStyles}>Logout</Text> </TouchableOpacity> )} 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<string> > => 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<string> => { const token = await AsyncStorage.getItem('token'); if (!token) { - dispatch({type: userLoggedIn.type, payload: {userId: '', username: ''}}); + dispatch(logout()); return ''; } return token; |