capacitor-firebase-auth icon indicating copy to clipboard operation
capacitor-firebase-auth copied to clipboard

'Google Sign In Failure' error on prompt dismissal (Android)

Open 5hee75 opened this issue 3 years ago • 8 comments

I am getting a Google Sign In Failure error reported from the plugin when I dismiss the Google sign in prompt. I am able to successfully sign in using the Google provider - I only get this error when I dismiss the sign in prompt. I would expect no error, or maybe the Firebase error code auth/popup-closed-by-user, which is the error thrown when you dismiss the sign-in dialog on the web.

I believe this is happening because of this function in GoogleProviderHandler.java:

    @Override
    public void handleOnActivityResult(int requestCode, int resultCode, Intent data) {
        Log.d(GOOGLE_TAG, "Google SignIn activity result.");

        try {
            Task<GoogleSignInAccount> task = GoogleSignIn.getSignedInAccountFromIntent(data);
            // Google Sign In was successful, authenticate with Firebase
            GoogleSignInAccount account = task.getResult(ApiException.class);

            if (account != null) {
                Log.d(GOOGLE_TAG, "Google Sign In succeed.");
                AuthCredential credential = GoogleAuthProvider.getCredential(account.getIdToken(), null);
                this.plugin.handleAuthCredentials(credential);
                return;
            }
        } catch (ApiException exception) {
            // Google Sign In failed, update UI appropriately
            Log.w(GOOGLE_TAG, GoogleSignInStatusCodes.getStatusCodeString(exception.getStatusCode()), exception);
            plugin.handleFailure("Google Sign In failure.", exception);
            return;
        }

        plugin.handleFailure("Google Sign In failure.", null);
    }

The exception is throw from the task.getResult(ApiException.class) line, because it does not first check the resultCode for the cancel case. https://stackoverflow.com/questions/50447430/google-sign-in-apiexception-12501-when-dismissing-the-sign-in-dialog

Error logcat

E/Capacitor/Plugin: Google Sign In failure.
    com.google.android.gms.common.api.ApiException: 12501: 
        at com.google.android.gms.common.internal.ApiExceptionUtil.fromStatus(com.google.android.gms:play-services-base@@17.1.0:4)
        at com.google.android.gms.auth.api.signin.GoogleSignIn.getSignedInAccountFromIntent(com.google.android.gms:play-services-auth@@18.0.0:9)
        at com.baumblatt.capacitor.firebase.auth.handlers.GoogleProviderHandler.handleOnActivityResult(GoogleProviderHandler.java:85)
        at com.baumblatt.capacitor.firebase.auth.CapacitorFirebaseAuth.handleOnActivityResult(CapacitorFirebaseAuth.java:178)
        at com.getcapacitor.Bridge.onActivityResult(Bridge.java:770)
        at com.getcapacitor.BridgeActivity.onActivityResult(BridgeActivity.java:212)
        at android.app.Activity.dispatchActivityResult(Activity.java:8294)
        at android.app.ActivityThread.deliverResults(ActivityThread.java:5248)
        at android.app.ActivityThread.handleSendResult(ActivityThread.java:5296)
        at android.app.servertransaction.ActivityResultItem.execute(ActivityResultItem.java:51)
        at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:135)
        at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:95)
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2229)
        at android.os.Handler.dispatchMessage(Handler.java:107)
        at android.os.Looper.loop(Looper.java:237)
        at android.app.ActivityThread.main(ActivityThread.java:8034)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1076)

5hee75 avatar Jul 14 '20 03:07 5hee75

Same issue here !

curiouscod3 avatar Jul 19 '20 04:07 curiouscod3

Same issue here. The front-end should be able to figure this out from the exception in plugin.handleFailure("Google Sign In failure.", exception), but capacitor doesn't seem to pass that exception back to the javascript layer. Maybe this plugin should send the exception code through instead

charlesj1 avatar Jul 31 '20 02:07 charlesj1

same issue as well. @baumblatt thoughts? :)

jeremyrajan avatar Aug 03 '20 08:08 jeremyrajan

is this issue still open.. i can fix it

priyanshnama avatar Aug 14 '20 11:08 priyanshnama

Yes. I am seeing the error :)

jeremyrajan avatar Aug 14 '20 14:08 jeremyrajan

ok

priyanshnama avatar Aug 14 '20 14:08 priyanshnama

@jeremyrajan Give me GoogleServcie.json file and other details please

priyanshnama avatar Aug 14 '20 14:08 priyanshnama

Same problem

lucascardial avatar Aug 27 '20 18:08 lucascardial