Skip to content

Commit

Permalink
docs(auth, google): forward-port google-signin example to v13+ APIs (#…
Browse files Browse the repository at this point in the history
…8092)

* fix: social auth Google sign in result
- Google sign in result type in the latest version of @react-native-google-signin/google-signin has changed
* make example code work with old or new API
* lint: result of `yarn lint:markdown --write`

---------

Co-authored-by: Mike Hardy <[email protected]>
  • Loading branch information
tolypash and mikehardy authored Oct 28, 2024
1 parent eac0a64 commit 43ebcde
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions docs/auth/social-auth.md
Original file line number Diff line number Diff line change
Expand Up @@ -312,10 +312,20 @@ async function onGoogleButtonPress() {
// Check if your device supports Google Play
await GoogleSignin.hasPlayServices({ showPlayServicesUpdateDialog: true });
// Get the users ID token
const { idToken } = await GoogleSignin.signIn();
const signInResult = await GoogleSignin.signIn();

// Try the new style of google-sign in result, from v13+ of that module
idToken = signInResult.data?.idToken;
if (!idToken) {
// if you are using older versions of google-signin, try old style result
idToken = signInResult.idToken;
}
if (!idToken) {
throw new Error('No ID token found');
}

// Create a Google credential with the token
const googleCredential = auth.GoogleAuthProvider.credential(idToken);
const googleCredential = auth.GoogleAuthProvider.credential(signInResult.data.token);

// Sign-in the user with the credential
return auth().signInWithCredential(googleCredential);
Expand Down

0 comments on commit 43ebcde

Please sign in to comment.