-
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
Storing Authentication Tokens clears the entire storage state and then repopulates causing extra storage events. #13583
Comments
Hello, @jon-armen and thanks for opening this issue. We'd recommend using the Hub utility for this use case based on what you've described in the issue. There's a Hub event emitted for the Auth channel specific to the And thank you for taking the time to submit a PR for this as well. We'll leave feedback/comments on it and follow up there. |
Hello @cwomack. In my use case, I'm not concerned about the tokenRefresh itself, I am needing to identify the I am close to achieving this using the local storage approach (although not as ideal as hub might be if it worked cross tabs), however the storage states receive two events during a refresh, which causes the other tabs to receive a clear and then a set operation. Ideally looking to track when the last signed in user id is changed (either to a different user or to null when signed out) |
@jon-armen, appreciate the follow up and additional context. Updating this issue to be a feature request for consideration and we'll review this further internally. If there's any additional questions or feedback for either this issue or the PR that you've submitted, we'll follow up accordingly. Thank you! |
Hi! We use amplify for authentication on our react-native app.
I've wrapped the Anyways, i've patched the library with the fix proposed by @jon-armen , and (for redundancy) also added a copy of the auth info using just the file-system. The refresh issue seems to be fixed (the last part is probably not needed, but I added redundancy just to be sure i wont have problems) |
@Manizuca, thanks for the follow up and tentative confirmation that @jon-armen's PR may resolve this! Quick question for you since you've tried it... when you say that you're restarting the app, do you mean that you're simply putting it in a background state or completely killing the app and all processes? |
@cwomack the time it happened to me was after killing the app, but i cannot confirm it was the same for the other reports i got |
@Manizuca, appreciate the quick reply and confirmation. We'll keep this as a feature request then at this point, and will follow up when progress is made or if we have more questions. |
Before opening, please confirm:
JavaScript Framework
Angular
Amplify APIs
Authentication
Amplify Version
v6
Amplify Categories
auth
Backend
None
Environment information
Describe the bug
Our application uses
localStorage
(the default) as the storage mechanism for Cognito Authentication Tokens. Using the shared storage mechanism, against all open browser tabs, we want to know when the authenticated user is changed (or signed out). We currently listen to the window storage events for local storage, which works great when users sign out. However, the implementation for assigning items to storage first clears the entire storage, and then populates storage. This causes an undesirable effect of appearing that the item is cleared from storage, and then inserted. I would consider this behavior a detriment to any storage back end implementation as every token refresh will have two operations - 1. delete existing item; 2. set new item value (if any). This would be better served instead by a single change to each storage key to either 1. delete existing item (if no new value); OR 2. set new item value.Expected behavior
When setting tokens, the number of accesses against each storage key should be reduced. We should not clear an item just to set it later in the code flow.
Reproduction steps
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
This is a proposed fix, which I will also submit a PR on.
The text was updated successfully, but these errors were encountered: