MaikuB / flutter_appauth

A Flutter wrapper for AppAuth iOS and Android SDKs
273 stars 246 forks source link

PlatformException(token_failed, Concurrent operations detected: token, token, null, null) #359

Open Dimple-Liberohealth opened 2 years ago

Dimple-Liberohealth commented 2 years ago

Hey, I went through all the comments in the previous issues, but still, nothing worked for me. I am continuously getting this error. Please help! MicrosoftTeams-image

.

biscottis commented 2 years ago

@Dimple-Liberohealth can you paste a code snippet of where this exception occurs?

ssorrychoi commented 2 years ago

I have same issue. so android user can't login :(

timnew commented 1 year ago

@MaikuB Maybe considering let exception caused by checkAndSetPendingOperation has a different error code? So it can be identified from flutter code easier. Or having an parameter to ignore the later call if previous one haven't finished?

Right now the only way to distinguish the concurrent operation error from the real error is by parsing the localized error message, as the token is always TOKEN_ERROR_CODE, which isn't really helpful in this case.

private void checkAndSetPendingOperation(String method, Result result) {
        if (pendingOperation != null) {
            throw new IllegalStateException(
                    "Concurrent operations detected: " + pendingOperation.method + ", " + method);
        }
        pendingOperation = new PendingOperation(method, result);
    }
timnew commented 1 year ago

I can make a PR for this change later, but right now, I'm quite occupied.

timnew commented 1 year ago

Go through the issue again, I think in general, ConcurrentOperation should be considered as an error instead of an exception in dart language semantics. As it is generated on by native code, so it is thrown as PlatformException, but in a ideal world, this case should be handled separately than the actual token exceptions.

MaikuB commented 1 year ago

@timnew Understand the error vs exception argument, however this is all based on how the Flutter APIs have been defined, which you can see in a number of places

As such, numerous plugins follow the same approach. In fact, I've modelled this particular one from one of Google's official plugins (see https://github.com/flutter/plugins/blob/cfbdcd0b40faabfbd345ea4d6498efd99affe838/packages/google_sign_in/google_sign_in_android/android/src/main/java/io/flutter/plugins/googlesignin/GoogleSignInPlugin.java#L320). Based on this, I would say it's working as designed. I haven't come across plugins trying to catch these and throw an error instead, which would likely make it more difficult to use tools like pigeon to generate code for plugins