-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathApp.js
More file actions
52 lines (45 loc) · 1.35 KB
/
Copy pathApp.js
File metadata and controls
52 lines (45 loc) · 1.35 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
import 'react-native-gesture-handler';
import React, { useEffect } from 'react';
import {NavigationContainer} from '@react-navigation/native';
import { SafeAreaProvider } from 'react-native-safe-area-context';
import BottomNavigator from './navigation/BottomNavigator';
import Login from './screens/login';
import {useSelector, useDispatch} from 'react-redux';
import axios from 'axios';
import AsyncStorage from '@react-native-async-storage/async-storage';
import Splash from './screens/splash';
import {checkAuthenticated} from './redux/actions';
axios.defaults.baseURL = 'http://13.233.143.137/api';
axios.interceptors.request.use(
async config => {
const token = await AsyncStorage.getItem('accessToken');
if (token) {
config.headers.Authorization = `Bearer ${token}`;
}
return config;
},
error => {
return Promise.reject(error);
},
);
function App() {
const dispatch = useDispatch();
const isAuthenticated = useSelector(state => state.isAuthenticated);
const appLoading = useSelector(state => state.appLoading);
useEffect(() => {
dispatch(checkAuthenticated());
}, [])
if (appLoading) {
return <Splash />
}
return (
<NavigationContainer>
{isAuthenticated ? <BottomNavigator /> : <Login />}
</NavigationContainer>
);
}
export default () => (
<SafeAreaProvider>
<App />
</SafeAreaProvider>
);