Google SignIn SDK is failing by throwing error, A non-recoverable sign in failure occurred -catch error: React Native

Viewed 16707

I have been trying to integrate Social login in my react native project in which I was able to do facebook login successfully but it is failing to signin to google. react-native-google-signin library is used for google.

The code I have used.

componentDidMount() {
GoogleSignin.hasPlayServices({ autoResolve: true }).then(() => {
// play services are available. can now configure library
}).catch((err) => {

console.log("Play services error", err.code, err.message);
})
GoogleSignin.configure({
scopes: ["https://www.googleapis.com/auth/drive.readonly"], // what API you want to access on behalf of the user, default is email and profile
// iosClientId: <FROM DEVELOPER CONSOLE>, // only for iOS
webClientId: "xxx", // client ID of type WEB for your server (needed to verify user ID and offline access)
// offlineAccess: true // if you want to access Google API on behalf of the user FROM YOUR SERVER
//hostedDomain: '' // specifies a hosted domain restriction
//forceConsentPrompt: true // [Android] if you want to show the authorization prompt at each login
//accountName: '' // [Android] specifies an account name on the device that should be used
})
.then(() => {
// you can now call currentUserAsync()
});
    _signIn = async () => {

        try {

            await GoogleSignin.hasPlayServices(

              )

          const userInfo = await GoogleSignin.signIn();
          console.log('User Info --> ', userInfo);
          this.setState({ userInfo });
        } catch (error) {

          console.log('Message', error.message);
          if (error.code ===  statusCodes.SIGN_IN_CANCELLED) {
            console.log('User Cancelled the Login Flow');
          } else if (error.code === statusCodes.IN_PROGRESS) {
            console.log('Signing In');
          } else if (error.code === statusCodes.PLAY_SERVICES_NOT_AVAILABLE) {
            console.log('Play Services Not Available or Outdated');
          } else {
            console.log('Some Other Error Happened');
          }
        }
      };

The error response:

Message: A non-recoverable sign in failure occurred -catch error
11 Answers

I know, I am very late to answer this question. I just faced the same issue and spent almost 4-5 hours to resolve this. The solution that I have found: "It starts working when I have added Support Email on Firebase" I think it's not the app or configuration issue. It may be a firebase issue that should be reported and nowhere in the doc.

Screenshot for Firebase settings

Apk link https://drive.google.com/file/d/1FNFBX-M7PQC6ShCC3KSuOH2E57YGPj6H/view?usp=sharing

 go to android folder  ./gradlew signingReport Take the SHA1 of Task

 :app:signingReport, Variant: debugAndroidTest, Config: debug Update

add fingure print sha1 in your project inside firebae.console.google.com

and download again google-service.json file in your project

enter image description here

enter image description here

enter image description here

[Error: A non-recoverable sign in failure occurred]

1. add support email to solve this error 
2. and wait 5 minutes your google login will be working fine

enter image description here

Following here

  • cd ./android && ./gradlew signingReport
  • Take the SHA1 of Task :app:signingReport, Variant: debugAndroidTest, Config: debug
  • Update it the Firebase Console under Project Settings, Android app, add the SHA1
  • Download the google-services.json, put it in ./android/app
  • Go to Authentication, then Sign-in method, then press Google
  • Take the Web client ID and use that for your GoogleSignin.configure({ webClientId: ... });
  • This Web client ID should be the same as listed in https://console.developers.google.com/apis/credentials?project=<your_project_id> -> Credentials -> OAuth 2 Client ID -> Web Client

run gradlew signingReport in the android folder and check all the sha1 listed and if you are using firebase then make sure that all the distinct sha1 found in the list is added to the firebase project then download the google-services.json again replace it with the old one in you project and run cd android && gradlew clean and build your project again

That's due to the clientId. In google developer console, When you configure the project for webClientID, instead of creating a new project choose an existing one, i.e create the project first and then choose it for creating credentials.

Create a new project first as of in below picture create a project this way

then choose that project from the list to create credentials enter image description here

It worked for me.

And coming to sign in configuration

GoogleSignin.hasPlayServices({ autoResolve: true }).then(() => {

})
.catch((err) => {
      console.log("Play services error", err.code, err.message);
})

GoogleSignin.configure({
     scopes: ["https://www.googleapis.com/auth/userinfo.profile"],//scopes as you need 
     webClientId: "***(Your clientId)",
     //iosClientId: <FROM DEVELOPER CONSOLE>, // only for iOS 
     //offlineAccess: true, //(give it true if you need serverAuthCode i.e cross client authorisation)
     //hostedDomain: '' 
     //forceConsentPrompt: true // [Android] if you want to show the authorization prompt at each login
     //accountName: ''
})

You need to add the support email. For that:-

  1. Go to console.firebase.google.com
  2. Select <YOUR_PROJECT> project.
  3. Go to project settings
  4. Under General tab scoll down to add support email. Add your email over there.

In my case, I've used the package name for my test app (ex. com.loginTest). After making my package name unique, I was able to solve this problem!

I searches and came across the following steps

  1. Enable OAuth on https://console.developers.google.com
  2. Copy and paste your SH1 while enabling
  3. Enable Google sign in on firebase authentication
  4. Use Oauth Client_Id instead of your WebClient ID

This fix could also help:

  1. Go to console.developer.google.com
  2. Select the project.
  3. Go to Credentials.
  4. Switch to O Auth Consent screen.
  5. Change the app name and fill email id (optional)
  6. Save at the bottom

Try logging in now and it should work.

Add support email in firebase and it will start working

Android

Make sure to follow these guidlines:

Dont forget to generate SHA-Keys and set them in your Firebase Console

with Simulator:

When testing on an Android Simulator, make sure GooglePlayServices are enabled. To prove this, add a few more lines to your SignInMethod:

const signInWithGoogle = async() => {
  // Wrap with try catch 
  try {
    await GoogleSignin.hasPlayServices({ showPlayServicesUpdateDialog: true }); // <-- Add this
    const { idToken } = await GoogleSignin.signIn();
    const googleCredential = auth.GoogleAuthProvider.credential(idToken);
    return auth().signInWithCredential(googleCredential);
  } catch (error) {
    // This will show you if GooglePlayServices is missing
    console.log('With high probability, GooglePlayServices are missing on this device');
    return;
  }
}
Related