-
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
Auth.currentSession does not refresh tokens automatically for some users specifically in android devices #13830
Comments
I am also facing the same issue. |
@ashishsoniDotsquares Are you also on Amplify JS version 5.x? |
Hi @nerdifydev, thanks for providing the details.
Do you have any details of the caught error, such as the message and error name it contained? Also regarding to this detail:
Can you elaborate? Do you mean you are preventing Amplify library from storing the auth token in the underlying AsyncStorage? Or do you mean you don't keep a reference to the object returned by a successful call of |
Hi @HuiSF, It says something like error - network error. It is something weird as users have proper network connectivity and it happens only when token expires. The token expires but does not renew, so for now, I had to set the ID token expiration to 24 hours and the refresh token to more than a month. |
Thanks for the addition details @nerdifydev, also and @ashishsoniDotsquares do you get the same error when this issue happened? Could you both determine, did this happen at a occasion, for example, when the end users reopened the Android app from background? Also are you able to collect details of the Android devices that encountered this issue, such as Android OS version, device type etc.? |
Hi @HuiSF,
|
Sorry about the segmented requests @nerdifydev could you also confirm, after the |
@HuiSF @haverchuck, I'm on version 5.3 and encountering a similar error where the token expires but does not refresh, causing the error to be caught in the catch block. This is somewhat unreliable, as I am seeing unauthorized requests from users on both older and the latest Android OS versions (10 to 14), across various devices (Samsung, Pixel, Moto, etc.).
Unfortunately, I don't have any specific data on whether this happens on particular occasions.
|
Hi @HuiSF,
Yes, as per the current functionality, we log users out of the app if an error occurs in Auth.currentSession, requiring them to sign in again. Upon re-signing, users receive a new token, so the error doesn't occur initially. However, when the token expires, Auth.currentSession is unable to renew it, and the cycle repeats. |
@nerdifydev this issue has helped us discover that on v5 specifically, the library is only attempting to retry on token revocation and on a network error that may raise due to intermittent disconnection. It's possible that this is the root cause of what's being reported in this issue. We're looking into how to make improvements to the retry logic for the v5 branch, and will update this issue to be a feature request specifically for v5 at this time. Thank you for your patience and taking the time to open this! |
Hi @cwomack, for your information, we are running on version 4 and we have the same issue. |
Thank you @cwomack @HuiSF for your prompt responses. I'm eagerly awaiting the next update and truly appreciate the effort being put into improving the retry logic for the v5 branch! |
Hi all, aws-amplify@5.3.25 is now released, it uses a retry logic now on failed service calls for refreshing sessions. |
@nerdifydev, can you upgrade to |
I'm also experiencing similar issues on v6. Will this fix also be applied to v6 or is this issue/fix only relevant to v5? |
@HuiSF we're also having the same issue on v6 ( We are also using React Native, and the issue does seem to happen primarily on Android devices (no reports of the issue on iOS yet from what I've seen). In our case, we are invoking
The user is most definitely still signed in, as we have The issue is not consistent or easy to reproduce. I tested by setting the ID and Access token expirations to 5 minutes (with |
Hi @danielshin @brianlenz in v6 the Please double check whether the access token is actually in the AsyncStorage of the react-native at the moment when you are calling In addition, in v6 all Auth service calls will be retired when a Network error occurs. |
@brianlenz, thank you for opening the v6 related issue! We'll follow up with you further (and anyone experiencing this in v6) there. @nerdifydev or anyone else on v5, please let us know if you can confirm if upgrading to the most recent version of v5 resolves the issue! |
I will upgrade to version 5.3.25 and let you know if the issue is resolved on my side. Additionally, I wanted to mention a valid use case pointed out by @brianlenz: even when the expiration time is set longer but some users' tokens tend to expire quite frequently, which does not trigger renewal might be on v5 as well. Thank you @brianlenz Thank you! |
@nerdifydev, wanted to circle back here and see if you had a chance to confirm if this is resolved. Let us know if you're still experiencing this bug! |
@nerdifydev, closing this issue as it should be resolved and we haven't heard back. Let us know if you're still experiencing this on the latest version of Amplify v5 and we can reopen if needed. Thanks! |
Before opening, please confirm:
JavaScript Framework
React Native
Amplify APIs
Authentication
Amplify Version
v5
Amplify Categories
auth
Backend
Amplify CLI
Environment information
Describe the bug
Auth.currentSession is not refreshing tokens automatically for some users, specifically on Android devices. I spent a lot of time debugging it, but I was never able to reproduce the issue, even when going offline for a while and coming back online to receive a new token before the token expiration. The issue seems somewhat unreliable, as I checked a few Android devices where the token was refreshing seamlessly. It throws an error in the catch block of Auth.currentSession. I'm not sure if there's a way to force a token refresh in Auth.currentSession with AWS Amplify v5 for React Native.
Also, I do not store tokens locally in the app and makes every time call to Auth.currentSession to fetch the latest token.
Expected behavior
Auth.currentSession should automatically refresh the token when it expires and should not throw an error in catch block of Auth.currentSession.
Reproduction steps
Note: The issue is not consistently reproducible, making it challenging to debug.
Code Snippet
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: