-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathApp.tsx
75 lines (69 loc) · 2.35 KB
/
App.tsx
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
import React from 'react';
import { BrowserRouter, Route, Switch } from 'react-router-dom';
import { ThemeProvider } from '@mui/material/styles';
import { ApolloProvider } from '@apollo/client';
import { setContext } from '@apollo/client/link/context';
import { SnackbarProvider } from 'notistack';
import theme from './theme';
import { LandingPage } from './_shared/pages';
import { PageNotFound } from './_shared/components/';
import { CollectionsLandingPage } from './collections/pages';
import { CuratedCorpusLandingPage } from './curated-corpus/pages';
import { ModerationLandingPage } from './moderation/pages';
import { useMozillaAuth } from './_shared/hooks';
import { client } from './api/client';
function App(): JSX.Element {
const {
canAccessCollections,
canAccessCuration,
canAccessModeration,
jwtIdToken,
} = useMozillaAuth();
// create an ApolloLink that adds the authorization header
const authLink = setContext((_, { headers }) => {
return {
headers: {
...headers,
authorization: jwtIdToken ? `Bearer ${jwtIdToken}` : '',
},
};
});
// concat the existing client link with our new authorization header link
// this will attach the auth header to all the requests that will be made
// that are wrapped by the ApolloProvider
client.setLink(authLink.concat(client.link));
return (
<ApolloProvider client={client}>
<ThemeProvider theme={theme}>
<SnackbarProvider maxSnack={3}>
<BrowserRouter>
<>
<Switch>
<Route exact path="/">
<LandingPage />
</Route>
{canAccessCollections && (
<Route path="/collections">
<CollectionsLandingPage />
</Route>
)}
{canAccessCuration && (
<Route path="/curated-corpus">
<CuratedCorpusLandingPage />
</Route>
)}
{canAccessModeration && (
<Route path="/moderation">
<ModerationLandingPage />
</Route>
)}
<Route component={PageNotFound} />
</Switch>
</>
</BrowserRouter>
</SnackbarProvider>
</ThemeProvider>
</ApolloProvider>
);
}
export default App;