-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathApp.js
49 lines (41 loc) · 1.19 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
import * as React from 'react';
import { StyleSheet } from 'react-native';
import Amplify, { Auth as AmplifyAuth } from 'aws-amplify'
import config from './aws-exports'
import Auth from './views/auth/Auth'
import Initializing from './views/Initializing'
import Main from './views/main/Home'
Amplify.configure(config)
class App extends React.Component {
state = {
currentView: 'initializing'
}
componentDidMount() {
this.checkAuth()
}
updateView = (currentView) => {
this.setState({ currentView })
}
checkAuth = async () => {
try {
const user = await AmplifyAuth.currentAuthenticatedUser()
console.log(user.getUsername(), 'is signed in')
this.setState({ currentView: 'main' })
} catch (err) {
console.log('user is not signed in')
this.setState({ currentView: 'auth' })
}
}
render() {
const { currentView } = this.state
console.log('currentView: ', currentView)
return (
<>
{ currentView === 'initializing' && <Initializing />}
{ currentView === 'auth' && <Auth updateView={this.updateView} />}
{ currentView === 'main' && <Main updateView={this.updateView} />}
</>
)
}
}
export default App;