Skip to content

Commit 43ebcde

Browse files
tolypashmikehardy
andauthored
docs(auth, google): forward-port google-signin example to v13+ APIs (#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]>
1 parent eac0a64 commit 43ebcde

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

docs/auth/social-auth.md

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -312,10 +312,20 @@ async function onGoogleButtonPress() {
312312
// Check if your device supports Google Play
313313
await GoogleSignin.hasPlayServices({ showPlayServicesUpdateDialog: true });
314314
// Get the users ID token
315-
const { idToken } = await GoogleSignin.signIn();
315+
const signInResult = await GoogleSignin.signIn();
316+
317+
// Try the new style of google-sign in result, from v13+ of that module
318+
idToken = signInResult.data?.idToken;
319+
if (!idToken) {
320+
// if you are using older versions of google-signin, try old style result
321+
idToken = signInResult.idToken;
322+
}
323+
if (!idToken) {
324+
throw new Error('No ID token found');
325+
}
316326

317327
// Create a Google credential with the token
318-
const googleCredential = auth.GoogleAuthProvider.credential(idToken);
328+
const googleCredential = auth.GoogleAuthProvider.credential(signInResult.data.token);
319329

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

0 commit comments

Comments
 (0)