forked from aws-samples/aws-amplify-quick-notes
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathApp.js
84 lines (76 loc) · 1.63 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
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
import React, { useEffect, useState } from "react";
import { Auth } from "aws-amplify";
import { Authenticator } from "aws-amplify-react";
import styled from "@emotion/styled";
import awsExports from "./aws-exports";
import Screens from "./components/Screens";
const Title = styled("h1")`
text-align: center;
text-transform: uppercase;
color: #a7d7c5;
margin-bottom: 8px;
`;
const theme = {
formContainer: {
margin: 0,
padding: "8px 24px 24px"
},
formSection: {
backgroundColor: "#ffffff",
borderRadius: "4px"
},
sectionHeader: {
color: "#74b49b"
},
sectionFooterSecondaryContent: {
color: "#303952"
},
inputLabel: {
color: "#74b49b"
},
input: {
backgroundColor: "#f4f9f4",
color: "#74b49b"
},
hint: {
color: "#74b49b"
},
button: {
borderRadius: "3px",
backgroundColor: "#a7d7c5"
},
a: {
color: "#a7d7c5"
}
};
function App() {
const [state, setState] = useState({ isLoggedIn: false, user: null });
const checkLoggedIn = () => {
Auth.currentAuthenticatedUser()
.then(data => {
const user = { username: data.username, ...data.attributes };
setState({ isLoggedIn: true, user });
})
.catch(error => console.log(error));
};
useEffect(() => {
checkLoggedIn();
}, []);
return state.isLoggedIn ? (
<Screens />
) : (
<>
<Title>Quick Notes Test</Title>
<Authenticator
onStateChange={authState => {
if (authState === "signedIn") {
checkLoggedIn();
}
}}
amplifyConfig={awsExports}
theme={theme}
/>
</>
);
}
export default App;