aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorankit-thanekar007 <ankit.thanekar007@gmail.com>2021-03-29 13:39:22 -0700
committerankit-thanekar007 <ankit.thanekar007@gmail.com>2021-03-29 13:39:22 -0700
commite8d862e5e6dd8a6a517a93c65e30795813af936d (patch)
tree3ed42fb2a394eb3a8dd5fa1dadd5881ea87eb7cd /src
parentbc1f377dfe4033f2fad28b7852dc09a72e0bd43e (diff)
Logout changes
Diffstat (limited to 'src')
-rw-r--r--src/screens/profile/SettingsScreen.tsx14
-rw-r--r--src/store/actions/user.ts2
-rw-r--r--src/utils/users.ts2
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;