-
Notifications
You must be signed in to change notification settings - Fork 0
/
App.js
75 lines (66 loc) · 1.71 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
import { StatusBar } from "expo-status-bar";
import React from "react";
import { StyleSheet, Text, View } from "react-native";
import config from './config';
import * as Google from 'expo-google-app-auth';
import LoggedInPage from './LoggedInPage';
import LoginPage from './LoginPage';
export default class App extends React.Component {
constructor(props) {
super(props)
this.state = {
signedIn: false,
name: "",
photoUrl: "",
accessToken: ""
}
}
signIn = async () => {
try {
console.log(config.OAUTH2_GOOGLE_ANDROID_KEY);
const result = await Google.logInAsync({
androidClientId: config.OAUTH2_GOOGLE_ANDROID_KEY,
scopes: ["profile", "email"],
});
if (result.type === "success") {
console.log(result);
this.setState({
signedIn: true,
name: result.user.name,
photoUrl: result.user.photoUrl,
accessToken: result.accessToken
})
return result.accessToken;
} else {
console.log("cancelled");
}
} catch (e) {
console.log("error", e);
}
};
onLogOut = () => {
console.log("onLogOut")
this.setState({
signedIn: false
})
}
render() {
return (
<View style={styles.container}>
{this.state.signedIn ? (
<LoggedInPage name={this.state.name} photoUrl={this.state.photoUrl} accessToken={this.state.accessToken} onLogOut={this.onLogOut}/>
) : (
<LoginPage signIn={this.signIn} />
)}
</View>
);
}
}
const styles = StyleSheet.create({
container: {
flex: 1,
backgroundColor: "darkorange",
alignItems: "center",
justifyContent: "center",
},
});