-
Notifications
You must be signed in to change notification settings - Fork 2.1k
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
User Sessions Discarded from AsyncStorage in Android #13930
Comments
Hi @brianlenz thanks for opening this issue. Could you help clarify:
When you were able to reproduce issue, did your app invoke only the Does your app automatically invoke any other Amplify APIs on resume to the foreground? From you description, when the AS contained only In addition, do you happen to have logs of the outgoing network requests around when the error occurred?
When you were able to reproduce the error, did you sign in the end user with version |
@HuiSF thanks so much for your attention and help 🙏
The log of the AsyncStorage happened before invoking
No, we do not. I audited the full startup process, and this component is essentially the first component rendered after we call
Unfortunately, I do not. Do you have any recommendations on the best way to capture these in RN?
These users were signed in with If the issue is with I'm going to keep adding more logs and trying to reproduce and debug to provide more insight 🤞 |
Thanks for the details @brianlenz
It sounds like you are rehydrate Redux state by reading data from AS, what AS APIs are you using for reading/updating the AS with your Redux store? |
We are using |
@HuiSF adding some additional context I forgot to mention originally. One other change that we made in this release is we switched from using Apollo Client (w/ We're still continuing to investigate, but thought I'd post this in case it triggers any ideas or thoughts on your end 🙏 |
Thanks for the additional information @brianlenz I was able to reproduce this unexpected token clearing. Apologies for my misunderstanding, the |
Great, thanks, @HuiSF! Was it happening on Android for you, too? We've not had a single complaint from iOS users. Note that in the most recent case where I reproduced the issue, the data was cleared in AS before Please do let me know if you identify reproduction steps, a root cause, or any potential workarounds (even if a patch or package downgrade). At this point, it's a particular pain point for our users, so I'm hoping to address is sooner than later. Thanks again! |
@HuiSF one more potentially relevant detail. We have a background handler for processing push notifications. This could explain why we're noticing a difference between Android and iOS, as they handle push notification processing differently. I noticed today in Android that one test emulator received a couple of "Unauthorized" errors when processing a push notification message (which was attempting to load data via GraphQL). What's interesting is that in spite of those errors, the user did remain signed in. |
@brianlenz, appreciate the follow up and additional context. We're looking into a fix and will follow up with any updates/progress as soon as we can! |
Hi @brianlenz we release v6.6.7 with should fix this unexpected token clearing behavior. Details please see the linked PR description. Please upgrade and test again, thanks! |
Thank you so much, @HuiSF! We will work on getting that tested and deployed to see if it fixes the issue. Did you have any good ideas of how to reliably reproduce the issue in Android so that we could confirm the issue exists on the current version and that it's fixed in |
Hi @brianlenz I was able to reproduce with the following conditions:
The expected behaviors is:
|
@HuiSF thanks so much for the fix here! 🙏 I can confirm that the issue has been resolved, so I'm going to close this 🚀 |
Thanks for the confirmation and creation of this issue, @brianlenz. |
Before opening, please confirm:
JavaScript Framework
React Native
Amplify APIs
Authentication, GraphQL API
Amplify Version
v6
Amplify Categories
auth, api
Backend
Amplify CLI
Environment information
Describe the bug
Similar to #13830 (which was for Amplify v5). I had reported what appeared to be the same issue in Amplify v6, but @HuiSF corrected me that it is actually unrelated, so I gathered more details to file this bug.
We are using React Native
0.75.4
withaws-amplify@npm:6.6.2
and@aws-amplify/auth@npm:6.4.2
. The issue appears to have started happening since we upgraded fromaws-amplify@npm:6.5.0
and@aws-amplify/auth@npm:6.3.13
. Note that as part of this upgrade, we also upgraded@react-native-async-storage/async-storage
from1.23.1
to the latest2.0.0
.The heart of the issue is that users in Android seem to get signed out of the app, typically after about a day. We have refresh tokens set to
3,650
days, so users should never be signed out automatically. To test, I set ID and access tokens to have a5
minute expiry. I've tested restarting the app after the 5 minute expiry numerous times within a 5-60 minute window, and I've not been able to reproduce the issue a single time that way. I have, however, reproduced the issue 3 times by simply waiting overnight and trying again in the morning. I don't know if there is any meaning behind that or if I've just been "lucky" to trigger whatever the root cause is.When the user remains signed in when launching the app, we can see all of the data as expected in AsyncStorage, e.g. with these keys:
When the bug here occurs, we only see one Congito entry in AsyncStorage:
Of course, since there are no tokens, the user is signed out.
We call
getCurrentUser()
at app launch, which is throwing theUserUnAuthenticatedException
since the tokens aren't found in AsyncStorage.I've turned on debug logging with
ConsoleLogger.LOG_LEVEL = 'DEBUG';
, but I don't see any logs from Amplify prior to seeing the data in AsyncStorage.There are no network errors or issues affecting these tests.
Is this a bug in Amplify? Is it possibly a bug in
@react-native-async-storage/async-storage
?Expected behavior
Tokens should remain in AsyncStorage, and users should remain signed in.
Reproduction steps
It's difficult to reproduce unfortunately. I've reproduced it 3 times out of about 100+ tests, most often after a 12+ hour delay in launching the app.
Code Snippet
// Put your code below this line.
Log output
aws-exports.js
No response
Manual configuration
No response
Additional configuration
No response
Mobile Device
No response
Mobile Operating System
No response
Mobile Browser
No response
Mobile Browser Version
No response
Additional information and screenshots
No response
The text was updated successfully, but these errors were encountered: