amplify-ui: fetchAuthSession triggering logout when offline
Before opening, please confirm:
- I have searched for duplicate or closed issues and discussions.
- I have read the guide for submitting bug reports.
- I have done my best to include a minimal, self-contained set of instructions for consistently reproducing the issue.
Fix can be found here: https://github.com/aws-amplify/amplify-ui/pull/6061
JavaScript Framework
React
Amplify APIs
Authentication
Amplify Version
v6
Amplify Categories
auth
Backend
CDK
Environment information
# Put output below this line
Describe the bug
If you call Auth.fetchAuthSession({ forceRefresh: true }) while offline, amplify will trigger the logout flow.
Expected behavior
I’d expect an error, but I wouldn’t expect to be logged out.
Reproduction steps
- Install latest version of AWS amplify with auth.
- Sign in.
- Go offline.
- Call
Auth.fetchAuthSession({ forceRefresh: true })(I did this by adding the function to the window).
Code Snippet
// Put your code below this line.
window.TRIGGER_ERROR = () => Auth.fetchAuthSession({ forceRefresh: true });
Log output
// Put your logs below this line
{"channel":"auth","payload":{"event":"tokenRefresh_failure","data":{"error":{"name":"NetworkError","underlyingError":{}}}},"source":"Auth","patternInfo":[]}
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
Related to https://github.com/aws-amplify/amplify-js/issues/13596 & https://github.com/aws-amplify/amplify-js/issues/13993
The below chunk of code is NOT responsible for clearing the tokens. I confirmed that the signout workflow is triggered further downstream.
If I return null (and prevent calling the subsequent Hub.dispatch) I am not logged out. Not sure what implications that will have so I didn’t submit a PR.
if (err.name !== AmplifyErrorCode.NetworkError) {
// TODO(v6): Check errors on client
this.clearTokens();
} else {
return null; // <-- Adding this "fixes" the issue
}
Hub.dispatch('auth', {
event: 'tokenRefresh_failure',
data: { error: err },
}, 'Auth', AMPLIFY_SYMBOL);
About this issue
- Original URL
- State: closed
- Created 2 years ago
- Reactions: 1
- Comments: 19 (17 by maintainers)
Commits related to this issue
- fix #6057 — committed to dehli/amplify-ui by dehli 2 years ago
The fix has been deployed with
@aws-amplify/ui@6.8.2. I’m closing out this issue as the release should resolve it, but if you’re running into further problems, please reply back and we can reopen and follow-up as needed. Thank you once again for your contributions!Sounds good! This seems to be what’s causing the behavior:
https://github.com/aws-amplify/amplify-ui/blob/2e3a051d9c2d48d5be22d2e83095cbd060ce2b40/packages/ui/src/helpers/authenticator/defaultAuthHubHandler.ts#L32-L36
@didemkkaslan Ideally you want log customer out when there is error except for Network error.
No custom storage. I’ll work on putting together a minimal reproducing example though 👍
@dehli @didemkkaslan Can you confirm which version are you both on? There was a retry fix just recently, while i see the issue on 6.6.4 (I used this version since that was what @didemkkaslan issue mentioned and on another issue as well) when i try the most recent version 6.8.0 i dont see the logout behavior anymore. Can one of you confirm ?
@dehli Thanks for taking a look. I can confirm i see the same behavior as well. I will look closer into this today and report back.
Having the same issue, I see tokenRefresh_failure event being fired and tokens are removed from cookie storage