1_signIn = async () => {
2 try {
3 await GoogleSignin.hasPlayServices();
4 const {accessToken, idToken} = await GoogleSignin.signIn();
5 setloggedIn(true);
6 } catch (error) {
7 if (error.code === statusCodes.SIGN_IN_CANCELLED) {
8 // user cancelled the login flow
9 alert('Cancel');
10 } else if (error.code === statusCodes.IN_PROGRESS) {
11 alert('Signin in progress');
12 // operation (f.e. sign in) is in progress already
13 } else if (error.code === statusCodes.PLAY_SERVICES_NOT_AVAILABLE) {
14 alert('PLAY_SERVICES_NOT_AVAILABLE');
15 // play services not available or outdated
16 } else {
17 // some other error happened
18 }
19 }
20};
1const [loggedIn, setloggedIn] = useState(false);
2const [userInfo, setuserInfo] = useState([]);
1return (
2 <>
3 <StatusBar barStyle="dark-content" />
4 <SafeAreaView>
5 <ScrollView
6 contentInsetAdjustmentBehavior="automatic"
7 style={styles.scrollView}>
8 <Header />
9
10 <View style={styles.body}>
11 <View style={styles.sectionContainer}>
12 <GoogleSigninButton
13 style={{width: 192, height: 48}}
14 size={GoogleSigninButton.Size.Wide}
15 color={GoogleSigninButton.Color.Dark}
16 onPress={this._signIn}
17 />
18 </View>
19 <View style={styles.buttonContainer}>
20 {!loggedIn && <Text>You are currently logged out</Text>}
21 {loggedIn && (
22 <Button
23 onPress={this.signOut}
24 title="LogOut"
25 color="red"></Button>
26 )}
27 </View>
28 </View>
29 </ScrollView>
30 </SafeAreaView>
31 </>
32 );
1signOut = async () => {
2 try {
3 await GoogleSignin.revokeAccess();
4 await GoogleSignin.signOut();
5 setloggedIn(false);
6 setuserInfo([]);
7 } catch (error) {
8 console.error(error);
9 }
10 };