-
Notifications
You must be signed in to change notification settings - Fork 0
/
App.js
134 lines (104 loc) · 2.61 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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
/**
* Sample React Native App
* https://github.com/facebook/react-native
*
* @format
* @flow strict-local
*/
import React from 'react';
import {StatusBar,LogBox} from 'react-native';
import Amplify from '@aws-amplify/core';
import { Auth as AmplifyAuth, AuthModeStrategyType, I18n } from 'aws-amplify';
import {Authenticator} from 'aws-amplify-react-native';
import {AmplifyTheme} from './src/components/amplifyTheme';
import MainNav from './src/pages/main/MainNav';
import { AmazonAIPredictionsProvider } from '@aws-amplify/predictions';
import dict from './src/data/translations/dict';
import awsconfig from './src/aws-exports';
LogBox.ignoreAllLogs(true);
Amplify.configure({
...awsconfig,
Analytics: {
disabled: true,
}
});
I18n.setLanguage('it');
I18n.putVocabularies(dict);
const signUpConfig = {
hideAllDefaults: true,
signUpFields: [
{
label: 'Email',
key: 'email',
required: true,
displayOrder: 1,
type: 'string',
},
{
label: 'Password',
key: 'password',
required: true,
displayOrder: 2,
type: 'password',
},
],
}
// export default App
class App extends React.Component {
constructor(props){
super(props);
Amplify.addPluggable(new AmazonAIPredictionsProvider());
this.state = {
currentView: 'initializing'
}
}
componentDidMount() {
this.checkAuth();
}
checkAuth = async () => {
try {
await AmplifyAuth.currentAuthenticatedUser()
console.log('user is signed in')
this.setState({ currentView: 'mainNav' })
} catch (err) {
console.log('user is not signed in')
this.setState({ currentView: 'auth' })
}
}
handleAuthStateChange = (state) => {
if (state === 'signedIn') {
/* Do something when the user has signed-in */
this.updateAuth(state);
}
}
updateAuth = (currentView) => {
this.setState({ currentView })
}
showComponents = () =>{
if(this.state.currentView == 'signedIn'){
return (
<MainNav updateAuth={this.updateAuth} currentView={this.state.currentView} />
);
}
// not logged
return (
<Authenticator
usernameAttributes="email"
signUpConfig={signUpConfig}
theme={AmplifyTheme}
onStateChange={this.handleAuthStateChange}
/>
);
}
render() {
const { currentView } = this.state;
console.log('currentView: ', currentView)
return (
<>
<StatusBar barStyle="light-content" />
{this.showComponents()}
</>
)
}
}
export default App