-
-
Notifications
You must be signed in to change notification settings - Fork 164
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
fix: refresh token sync across multiple tabs #461
Conversation
error instanceof AuthRetryableFetchError && | ||
this.networkRetries < NETWORK_FAILURE.MAX_RETRIES | ||
) | ||
this._startAutoRefreshToken(NETWORK_FAILURE.RETRY_INTERVAL ** this.networkRetries * 100) // exponential backoff |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this seems error prone too - in the event of network failure, the retry interval could possibly fall outside of the reuse interval error but currently the client has no way of knowing what the reuse interval is
i think it's safe to assume that if the network failure lasts longer than the reuse interrval, then the user should be forced to login again
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, I agree with you that the user should be logged out here. We can always take another look at this if it becomes a bigger issue in the future.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@kangmingtay, @alaister. A robust approach could be to listen for a network status change.
https://developer.mozilla.org/en-US/docs/Web/API/Navigator/onLine
This could affect users who are traveling and have their laptops offline for a day. Ideally, you'd want to stay logged in, it's an edge case, but a listener would capture these events. Then you can avoid long polling.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm!
error instanceof AuthRetryableFetchError && | ||
this.networkRetries < NETWORK_FAILURE.MAX_RETRIES | ||
) | ||
this._startAutoRefreshToken(NETWORK_FAILURE.RETRY_INTERVAL ** this.networkRetries * 100) // exponential backoff |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, I agree with you that the user should be logged out here. We can always take another look at this if it becomes a bigger issue in the future.
🎉 This PR is included in version 2.0.0-rc.7 🎉 The release is available on: Your semantic-release bot 📦🚀 |
What kind of change does this PR introduce?
_startAutoRefreshToken
used to take in the current session which might go stale by the time thesetTImeout
callback is invoked_startAutoRefreshToken
to always get the current session from storage / memory instead of relying on thesession
passed inJWT_EXPIRY
: 30s,REUSE_INTERVAL
: 10s, 5 tabs opened (firefox)JWT_EXPIRY
: 20s,REUSE_INTERVAL
: 5s, 5 tabs opened (firefox)