-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathApp.js
50 lines (45 loc) · 1.33 KB
/
App.js
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
import 'react-native-gesture-handler';
import React, {useState, useEffect} from 'react';
import {StatusBar} from 'react-native';
import MainNavigator from './src/navigators/MainNavigator';
import {ApolloClient, InMemoryCache, createHttpLink} from '@apollo/client';
import {setContext} from '@apollo/client/link/context';
import { ApolloProvider } from '@apollo/client/react';
import {GRAY} from './src/constants/colors';
import AsyncStorage from '@react-native-async-storage/async-storage';
import {url} from './config.js';
console.log(url, 'url');
const httpLink = new createHttpLink({
uri: url,
});
const authLink = setContext(async (_, {headers}) => {
// get the authentication token from local storage if it exists
const token = await AsyncStorage.getItem('token');
// return the headers to the context so httpLink can read them
return {
headers: {
...headers,
authorization: token ? `Bearer ${token}` : '',
},
};
});
const client = new ApolloClient({
cache: new InMemoryCache(),
link: authLink.concat(httpLink),
});
const App = () => {
return (
<>
<ApolloProvider client={client}>
<StatusBar
barStyle="dark-content"
backgroundColor={GRAY.T2}
translucent
/>
<MainNavigator />
</ApolloProvider>
</>
);
};
export {client};
export default App;