-
Notifications
You must be signed in to change notification settings - Fork 441
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Unable to navigate away from Auth Component when Android OS destroys Activity #360
Comments
We are having similar issues on certain production user devices where the app just seems to restart after the authentication flow is complete, leaving the user in an unauthenticated state. Wasn't able to reproduce this myself earlier, but now setting the "Don't Keep Activities" developer option makes the bug really apparent. This seems to be quite a large omission of the library. Not supporting completion of the authentication flow from a cold start seems to have caused quite a lot of different bug reports in the repo, but none seem to have fixed the underlying issue of handling the case where the original activity has been destroyed. For reference, here is a screencast of the issue reproduced in the example app: Just to make sure that this is not an issue with the underlying AppAuth-Android library, I verified that it works with their sample app: |
For some additional context about why Android kills activities see https://developer.android.com/guide/components/activities/activity-lifecycle#asem. Here is also a longer developer point of view for how to think about testing and handling killed activities https://medium.com/mindorks/hey-android-please-keep-my-activities-7bf96ccc0a38 |
Playing around with the example app, I noticed that the React Native JS runtime seems to persist between the separate Android activities. As @AlteaDown mentioned earlier, this means that the original promise is still resolved, but the React component handling the result is not attached anymore. But this also means that the issue could likely be worked around by using some global JavaScript variable to transfer authentication responses between separate instances of the React Native app root component. This would of course doesn't work in cases where the whole application is closed in the background, but I guess this is a bit rarer case. Nonetheless, it would be nice for the library to provide some support on how to best handle these situations. |
Closing and moving discussion to #743 as that captures the issue and links to the upstream repo. |
Issue
The library can't seem to handle cases where
Activity.onDestroy()
is called when authenticating. Authentication is performed in a WebView separate from the Android Activity that is running RN, so that means when we move to it, the RN Activity is put on the backstack, and Android is now free to have theActivity.onDestroy()
called on the Activity.When
Activity.onDestroy()
is called on the RN Activity, and once authentication succeeds, the library attempts to launch the previous activity again (but it was destroyed so it needs to be recreated). So we end up with a new Activity/Component that is completely unrelated to the authorize call we originally made.Some time after the new activity is done loading, our original call to
authorize()
will get a response from the token endpoint. However, the Component is detached, and unable to handle rendering. This means that if you want to navigate to a new Component, such as the rest of your app, you can not. The only way I can imagine being able to handle this is, first being aware that this situation can arise, when it does arise, and then to actually know that the state has changed on the new Component, you would have to use a reactive structure like a RxJS Subject that will emit to the new Component to allow it to handle this case, when it occurs.You can recreate this scenario easily by using the "Don't Keep Activities" setting in your android Device's Developer Settings, or by using a low performance/low memory Android device.
Example code
Environment
Android
The text was updated successfully, but these errors were encountered: