-
Notifications
You must be signed in to change notification settings - Fork 0
/
App.js
59 lines (51 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
import { StatusBar } from "expo-status-bar";
import { StyleSheet } from "react-native";
import Navigator from "./src/navigation";
import { Amplify, Auth, API, graphqlOperation } from "aws-amplify";
import { withAuthenticator, Analytics } from "aws-amplify-react-native";
import awsconfig from "./src/aws-exports";
import { useEffect } from "react";
import { getUser } from "./src/graphql/queries";
import { createUser } from "./src/graphql/mutations";
Amplify.configure({ ...awsconfig, Analytics: { disabled: true } });
function App() {
useEffect(() => {
const fetchUser = async () => {
// TO CREATE USER IN THE DB UPON SIGNING UP
// get Auth user
const authUser = await Auth.currentAuthenticatedUser({
bypassCache: true,
});
// query the database using Auth user id (sub)
const userId = authUser.attributes.sub;
const userData = await API.graphql(
graphqlOperation(getUser, { id: userId })
);
// if there is no users in db, create
if (userData.data.getUser === null) {
const newUser = {
id: userId,
name: "Mock Name",
status: "Disponible",
// dummy image
image:
"https://raw.githubusercontent.com/Rmarieta/ChatAppReactNative/backend/assets/users/dummy_user.png",
};
const res = await API.graphql(
graphqlOperation(createUser, {
input: newUser,
})
);
}
};
fetchUser();
}, []);
return (
<>
<Navigator />
<StatusBar style="light" />
</>
);
}
export default withAuthenticator(App);
const styles = StyleSheet.create({});