Reputation: 56
I am using this code for signing in with @react-native-google-signin/google-signin
on my expo react native app
async function onGoogleButtonPress() {
try {
// Start Google Sign-In process
await GoogleSignin.hasPlayServices();
const userInfo = await GoogleSignin.signIn();
// Get the idToken from Google
const googleCredential = auth.GoogleAuthProvider.credential(userInfo.idToken, userInfo.accessToken);
// Now sign in to Firebase using the idToken
await auth().signInWithCredential(googleCredential);
console.log('User signed in with Google!', userInfo);
} catch (error) {
if (error.code === statusCodes.SIGN_IN_CANCELLED) {
console.error('User cancelled Google Sign-In');
} else if (error.code === statusCodes.IN_PROGRESS) {
console.error('Sign-In in progress');
} else {
console.error('Something went wrong with Google Sign-In:', error);
}
}
}
I can get all the way to the end of the google sign in screen, but after the website closes it gives this error
Something went wrong with Google Sign-In: [Error: [auth/internal-error] An internal error has occurred, please try again.]
After intercepting the requests I come across a request to https://www.googleapis.com/identitytoolkit/v3/relyingparty/verifyAssertion?key=<key>
which responds back with a 400 status code and this response body
{ "error": { "code": 400, "message": "INVALID_CREDENTIAL_OR_PROVIDER_ID : Invalid IdP response/credential: http://localhost?providerId=google.com&id_token&access_token", "errors": [ { "message": "INVALID_CREDENTIAL_OR_PROVIDER_ID : Invalid IdP response/credential: http://localhost?providerId=google.com&id_token&access_token", "domain": "global", "reason": "invalid" } ] } }
My GoogleService-Info.plist
and google-services.json
are all up to date.
As far as I can tell, its making it to the
await auth().signInWithCredential(googleCredential);
and then throwing the error on that line.
Upvotes: 0
Views: 54
Reputation: 56
I figured it out after looking deeper into the docs. Turns out that the example code
import auth from '@react-native-firebase/auth';
import { GoogleSignin } from '@react-native-google-signin/google-signin';
async function onGoogleButtonPress() {
// Check if your device supports Google Play
await GoogleSignin.hasPlayServices({ showPlayServicesUpdateDialog: true });
// Get the users ID token
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(signInResult.data.token);
// Sign-in the user with the credential
return auth().signInWithCredential(googleCredential);
}
was written wrong and should have used
auth.GoogleAuthProvider.credential(signInResult.data.idToken);
rather than
auth.GoogleAuthProvider.credential(signInResult.data.token);
Upvotes: 0