react-native-google-signin / google-signin

Google Sign-in for your React Native applications
https://react-native-google-signin.github.io/
MIT License
3.13k stars 876 forks source link

Error Code 12501: Sign in action cancelled #1148

Closed BrodaNoel closed 1 year ago

BrodaNoel commented 1 year ago

Steps to Reproduce

Reproducible Demo: In this scenario, due to it's 99% a configuration problem, I won't be able to create a reproducible demo.

Even worst: I have this library implemented in 2 projects, where one of them is working perfectly (using Expo 46), and this one is broken (tried with Expo 46, 47 and 48).

I can't really reproduce this in my app (not even in simulators like BrowserStack), but I've seen that ~50% of the Android users are getting that error (Error Code 12501: Sign in action cancelled) and they just can't login.

This is the code I have, which is EXACTLY the same I have in another project and it's working perfectly in the other one:

import { GoogleSignin } from '@react-native-google-signin/google-signin';

// ...

onContinueWithGoogle = async () => {
  let hasPlayServices;
  try {
    GoogleSignin.configure();

    hasPlayServices = await GoogleSignin.hasPlayServices();
    const { user } = await GoogleSignin.signIn();
    // ^^^ Here is there I'm getting the error

    // More code here, but never gets executed
  } catch (error) {
    actions.analytics.track('LOGIN_CONTINUE_ERROR', {
      platform: 'google',
      message: error.message,
      code: error.code,
      hasPlayServices,
    });
  }
};
Screen Shot 2023-03-05 at 19 28 54

I am using Firebase.

I already went to Google Play > Releases > App Integrity > App Signing, and copied the SHA-1 from App signing key certificate AND from Upload key certificate. I added both SHA-1 in Firebase > Project Settings > General > Your Apps > Android apps. Both are there.

After adding those SHA-1, I downloaded the google-services.json file and I added it to the project in the root folder.

My app.json file look like:

{
  "expo": {
    "ios": {
      "googleServicesFile": "./GoogleService-Info.plist",
    },
    "android": {
      "googleServicesFile": "./google-services.json",
      "permissions": [
        "android.permission.ACCESS_COARSE_LOCATION",
        "android.permission.ACCESS_FINE_LOCATION",
        "android.permission.READ_EXTERNAL_STORAGE",
        "android.permission.WRITE_EXTERNAL_STORAGE",
        "android.permission.ACCESS_MEDIA_LOCATION",
        "android.permission.INTERNET"
      ],
      "blockedPermissions": [
        "android.permission.CAMERA",
        "android.permission.RECORD_AUDIO",
        "com.google.android.gms.permission.AD_ID"
      ]
    },
    "plugins": [
      "sentry-expo",
      "@react-native-google-signin/google-signin"
    ]
  }
}

And the google-services.json file look like this:

{
  "project_info": {
    "project_number": "xxx",
    "project_id": "mrodis",
    "storage_bucket": "xxx"
  },
  "client": [
    {
      "client_info": {
        "mobilesdk_app_id": "xxxx",
        "android_client_info": {
          "package_name": "xxx"
        }
      },
      "oauth_client": [
        {
          "client_id": "1082xxxxx",
          "client_type": 1,
          "android_info": {
            "package_name": "com.mrodis.app",
            "certificate_hash": "d6[this hash is the SHA-1 for 'Upload key certificate' from Google Play]"
          }
        },
        {
          "client_id": "10822xxxxx",
          "client_type": 1,
          "android_info": {
            "package_name": "com.mrodis.app",
            "certificate_hash": "147eb[this hash is the SHA-1 for 'App signing key certificate' from google play]"
          }
        },
        {
          "client_id": "1082xxxxxxxxxxx",
          "client_type": 3
        }
      ],
      "api_key": [
        {
          "current_key": "AIzxxxxxx"
        }
      ],
      "services": {
        "appinvite_service": {
          "other_platform_oauth_client": [
            {
              "client_id": "108226xxxxxx",
              "client_type": 3
            },
            {
              "client_id": "1082xxxxx",
              "client_type": 2,
              "ios_info": {
                "bundle_id": "com.mrodis.app",
                "app_store_id": "xxxxx"
              }
            }
          ]
        }
      }
    }
  ],
  "configuration_version": "1"
}

So, as far as you can see, the SHA-1 are there, and are the same in Google Play, and Firebase, and in the google-services file. But the error 12501 still there. And as far as I can see, the error 12501 means that the app was signed with other key.

I have already tried 1000 different changes (even removing all the keys and adding them again), and nothing works. I can't see a difference between the project where it works and this. The only difference is that in the other project it worked since ~1 year ago, and there I'm using 8.0.0.

If I go to see eas credentials (for expo), I see that the SHA-1 for building is D6:1C:xxxx, which is the same it's present in Firebase. So... I don't know πŸ€·πŸΌβ€β™‚οΈ

Expected Behavior

Error should not be present and the user should be able to create the account/login

Actual Behavior

Throwing an error, catched by the try-catch. Check code.

Environment

vendeza commented 1 year ago

https://github.com/react-native-google-signin/google-signin the problem is related to the new React Native architecture. It's weird that no one has been contributing a solution for 2 years.

BrodaNoel commented 1 year ago

@vendeza how sure are you? Do you have any way to confirm that's the reason? It may help to fix the problem.

@vonovak because I'm totally blocked by this issue (in 2 projects!), I'm willing to make some donation for this. How much would it be enough for supporting this? Please attach the link for the "one-time" donation!

vonovak commented 1 year ago

@BrodaNoel hello and thanks for reporting. I'm fairly certain this has nothing to do with the new architecture, unless you have it enabled (which you most likely don't have, given that you use expo - I don't think they allow it yet).

I appreciate your interest in donating for the project, all options are listed here πŸ™‚ .

However, sponsorships are meant to support maintaining the project, or as a way to say "thanks". The problem you're having appears to be a more complicated one, something that could take several hours to diagnose and fix. If you're interested in getting help from me (as a paid service) please send me an email to hello@react-native-training.eu or DM me at https://twitter.com/vonovak

Thank you πŸ‘

BrodaNoel commented 1 year ago

Expo is using new architecture since SDK 47. So, since 5 months ago.

https://blog.expo.dev/expo-sdk-48-ccb8302e231?source=collection_home---6------1-----------------------

BrodaNoel commented 1 year ago

@vonovak what I don't understand is what is the relationship between the New Arch being used in Expo, and this library? If this library is not using the New Arch, there should not be a problem.

vonovak commented 1 year ago

Hello again, expo is not using new architecture. It is supported but not enabled by default. So unless you enabled it, it's not enabled.

Yes, this library is not using new architecture and your app neither. It should not be a problem πŸ™‚

BrodaNoel commented 1 year ago

I am seeing some kind of pattern now. This is what Sentry shows:

Screen Shot 2023-03-07 at 10 21 30
vonovak commented 1 year ago

@BrodaNoel not sure how big the sample is (probably small)? But I'm not really seeing much useful info there. It shows that the problem spans from android 6 all the way up πŸ€”. That's probably all android versions that your app supports. What do you see?

atif089 commented 4 months ago

@BrodaNoel did you ever get this to work? I'm stuck in the same situation for a couple of days now.

atif089 commented 4 months ago

My Java is quite poor so pardon me if I'm wrong but looking at this code my interpretation is that if the sign-in function is called multiple times it cancels the previous one.

In my case, please don't ask me how, but this fixed it for me.

image

@BrodaNoel You can check in your code, maybe you also have re-renders or multiple executions of onContinueWithGoogle, hence causing the same issue.

BrodaNoel commented 4 months ago

@vonovak have you checked that comment? Maybe that's the fix.

@atif089 i don't have that error anymore but because I did A LOT of refactors in my code. Maybe one of those refactors removed some double rendering and fixed it. I am not seeing that error in Sentry anymore (Expo SDK 49)