-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathApp.js
More file actions
89 lines (76 loc) · 2.4 KB
/
App.js
File metadata and controls
89 lines (76 loc) · 2.4 KB
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
import React from 'react';
import { StyleSheet, Text, View, TouchableOpacity, Button } from 'react-native';
import {createStackNavigator, createAppContainer} from 'react-navigation';
// AWS Amplify
import Amplify from 'aws-amplify';
import { Auth, API, graphqlOperation } from 'aws-amplify';
import { withAuthenticator } from 'aws-amplify-react-native';
import { listUsers } from './src/graphql/queries';
import { createUser } from './src/graphql/mutations';
// AWS config file
import AWSConfig from './aws-exports';
// All Views
import Main from './src/views/Main';
import NewNote from './src/views/NewNote';
import Note from './src/views/Note';
import Profile from './src/views/Profile';
// Components
import Map from './src/components/Map';
// Navigation stack
const AppNavigator = createStackNavigator(
{
Main: Main,
NewNote: NewNote,
Note: Note,
Profile: Profile,
Map: Map
},
{
initialRouteName: 'Main'
}
);
// AWS config
Amplify.configure(AWSConfig);
const AppContainer = createAppContainer(AppNavigator);
class App extends React.Component {
componentDidMount() {
Auth.currentAuthenticatedUser()
.then(user => {
this.setState({ username: user.username });
this.checkNewUser(user);
})
.catch(err => console.log(err));
}
// check if current authenticated user is in database
// if not, then create new user to database
checkNewUser(user) {
(async () => {
const data = await API.graphql(graphqlOperation(listUsers, {
filter: { username: { eq: user.username } }
}));
console.log(data.data.listUsers);
if(data.data.listUsers.items.length == 0) {
API.graphql(graphqlOperation(createUser, {
input: {
username: user.username,
email: user.attributes.email,
emailVerified: user.attributes.email_verified
}
}))
.then(data => console.log("New User Created: " + data.data.createUser.username));
}
})();
}
render() {
return <AppContainer />;
}
}
export default withAuthenticator(
App,
{
includeGreetings: true,
signUpConfig: {
hiddenDefaults: ['phone_number']
}
}
);