install react-native-google-singin code example
Example 1: how to add oAuth google signin in react native app
import { GoogleSignin, GoogleSigninButton } from 'react-native-google-signin';
render() {
<GoogleSigninButton
style={{ width: 192, height: 48 }}
size={GoogleSigninButton.Size.Wide}
color={GoogleSigninButton.Color.Dark}
onPress={this._signIn}
disabled={this.state.isSigninInProgress} />
};
Example 2: google login with react native
_signIn = async () => {
try {
await GoogleSignin.hasPlayServices();
const {accessToken, idToken} = await GoogleSignin.signIn();
setloggedIn(true);
} catch (error) {
if (error.code === statusCodes.SIGN_IN_CANCELLED) {
alert('Cancel');
} else if (error.code === statusCodes.IN_PROGRESS) {
alert('Signin in progress');
} else if (error.code === statusCodes.PLAY_SERVICES_NOT_AVAILABLE) {
alert('PLAY_SERVICES_NOT_AVAILABLE');
} else {
}
}
};
Example 3: google login with react native
const [loggedIn, setloggedIn] = useState(false);
const [userInfo, setuserInfo] = useState([]);