1 |
react-native link react-native-google-signin |
1 2 3 4 5 6 |
<GoogleSigninButton style={styles.googleButton} size={GoogleSigninButton.Size.Wide} color={GoogleSigninButton.Color.Dark} onPress={this.signIn} /> |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
signIn = async () => { try { GoogleSignin.configure(); await GoogleSignin.hasPlayServices(); const userInfo = await GoogleSignin.signIn(); this.setState({userInfo}, () => { console.log(this.state.userInfo); }); //log in is success! } catch (error) { console.log(error); if (error.code === statusCodes.SIGN_IN_CANCELLED) { // user cancelled the login flow } else if (error.code === statusCodes.IN_PROGRESS) { // operation (f.e. sign in) is in progress already } else if (error.code === statusCodes.PLAY_SERVICES_NOT_AVAILABLE) { // play services not available or outdated } else { // some other error happened } } }; |
1 2 3 4 5 6 7 8 |
isSignedIn = async () => { const isSignedIn = await GoogleSignin.isSignedIn(); if (isSignedIn) { //the user is already signed in } else { //the user is not logged in yet } }; |