-
Notifications
You must be signed in to change notification settings - Fork 27
/
App.tsx
70 lines (66 loc) · 1.96 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
import './App.css';
import { Amplify, Auth } from 'aws-amplify';
import config from './config';
import '@aws-amplify/ui-react/styles.css';
import Stats from './components/stats';
import { Authenticator, Button, useAuthenticator } from '@aws-amplify/ui-react';
import Memo from './components/memo';
import { AppBar, Container, Toolbar, Typography } from '@mui/material';
function App() {
const amplifyConfig = {
...(true || config.userPoolId != null
? {
Auth: {
region: config.awsRegion,
userPoolId: config.userPoolId,
userPoolWebClientId: config.userPoolClientId,
},
}
: {}),
API: {
endpoints: [
{
name: 'main',
endpoint: config.apiEndpoint,
custom_header: async () => {
return { Authorization: `${(await Auth.currentSession())?.getAccessToken().getJwtToken()}` };
},
},
{
name: 'public',
endpoint: config.apiEndpoint + '/public',
},
],
},
};
Amplify.configure(amplifyConfig);
const { authStatus } = useAuthenticator((context) => [context.user]);
return (
<>
{authStatus != 'authenticated' ? <Stats></Stats> : <></>}
<Authenticator>
{({ signOut, user }) => (
<>
<AppBar position="static">
<Toolbar>
<Typography variant="h6" color="inherit" noWrap sx={{ flexGrow: 1 }}>
Write your memo
</Typography>
<Typography sx={{ paddingX: 2 }}>{user == null ? '' : user.username}</Typography>
<Button color="inherit" onClick={signOut}>
Sign out
</Button>
</Toolbar>
</AppBar>
<main>
<Container maxWidth="lg" sx={{ m: 2 }}>
<Memo />
</Container>
</main>
</>
)}
</Authenticator>
</>
);
}
export default App;