-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathApp.js
More file actions
110 lines (98 loc) · 3.04 KB
/
Copy pathApp.js
File metadata and controls
110 lines (98 loc) · 3.04 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
import 'react-native-gesture-handler';
import React from 'react';
import { NavigationContainer } from '@react-navigation/native';
import { createStackNavigator } from '@react-navigation/stack';
import Login from './Apps/login';
import Main from './Apps/Main';
import SignIn from './Apps/signin';
import Review from './Apps/Review';
import Account from './Apps/Account';
import Activity from './Apps/Accounts/Activity';
import Help from './Apps/Accounts/Help'
import Settings from './Apps/Accounts/Settings'
import Resume from './Apps/Resume'
import Post from './Apps/Post'
import PostDetails from './Apps/PostDetails';
import Community from './Apps/Community';
import { useEffect } from 'react';
const Stack = createStackNavigator();
const App = () => {
const checkAutoLogin = async () => {
const token = await EncryptedStorage.getItem('access_token');
if (token) {
try {
const response = await fetch('http://localhost:3000/login/verify-token', {
method: 'POST',
headers: {
'Authorization': `Bearer ${token}`,
'Content-Type': 'application/json'
}
});
if (response.ok) {
navigation.navigate('Main'); // If token is valid, skip login
} else {
navigation.navigate('Login'); // If token is invalid, show login
}
} catch (error) {
console.error('Error verifying token:', error);
navigation.navigate('Login'); // Show login on error
}
} else {
navigation.navigate('Login'); // No token, show login
}
};
useEffect(() => {
checkAutoLogin();
}, []);
return (
<NavigationContainer>
<Stack.Navigator initialRouteName="Login">
<Stack.Screen
name="Login"
component={Login}
options={{ headerShown: false }}
/>
<Stack.Screen
name="Main"
component={Main}
options={{ headerShown: false }}
/>
<Stack.Screen
name="SignIn"
component={SignIn}
options={{ headerShown: false }}
/>
<Stack.Screen
name="Review"
component={Review}
options={{ headerShown: false }}
/>
<Stack.Screen
name="Account"
component={Account}
options={{ headerShown: false }}
/>
<Stack.Screen
name="Resume"
component={Resume}
options={{ headerShown: false }}
/>
<Stack.Screen
name="PostDetails"
component={PostDetails}
options={{ headerShown: false }}
/>
<Stack.Screen
name="Community"
component={Community}
options={{ headerShown: false }}
/>
<Stack.Screen name="Activity" component={Activity} />
<Stack.Screen name="Settings" component={Settings} />
<Stack.Screen name="Help" component={Help} />
<Stack.Screen name="Post" component={Post} />
</Stack.Navigator>
</NavigationContainer>
);
};
export default App;