auth0 / Auth0.Android

Android toolkit for Auth0 API
https://auth0.com
MIT License
219 stars 133 forks source link

AndroidRuntimeException when calling `await(context)` #607

Closed sdetord closed 2 years ago

sdetord commented 2 years ago

Describe the problem

When using the library with coroutines the app throws an AndroidRuntimeException with the message:

Calling startActivity() from outside of an Activity context requires the FLAG_ACTIVITY_NEW_TASK flag. Is this really what you want?

What was the expected behavior?

Not getting an exception

Reproduction

            val result = runCatching {
                val credentials = try {
                    WebAuthProvider.login(account)
                        .withAudience(context.getString(R.string.auth0_client_audience))
                        .await(context)
                } catch (e: Exception) {
                    // Exception caught here. The context is the Activities `baseContext` which should be able to `startActivity`s.
                    Log.d("Auth0", "exception: $e")
                    throw e
                }
            }

Environment

poovamraj commented 2 years ago

Hi @sdetord, I tried to reproduce this issue but couldn't. Following details could help more

I tried to do it from background thread, but the library rightly switched to main thread before starting the Web Authentication

sdetord commented 2 years ago

Hello @poovamraj. After some changes to the codebase I no longer have the crash. I unfortunately had forgotten that I filed this issue so I didn't come back to report what I had changed. Given that this problem used to be 100% reproducible and now I never get it I'm guessing it was a problem on my side.

Thank you very much for taking the time to respond and sorry about not informing you about the updates sooner.

Cheers

poovamraj commented 2 years ago

No problem :) Glad it is fixed now. If possible, you can let us know what changed to make this work so that any future developer facing this same issue can fix it or we can try to handle such edge cases on the library side itself.

I'll close this issue for now but please feel free to reopen it if you have anymore doubts regarding this issue.