-
-
Notifications
You must be signed in to change notification settings - Fork 172
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
2.0.5 is generating multiple refresh requests per refresh cycle #529
Comments
Believe I found the issue. Was introduced with gotrue-js v2.2.2 - which is the version required in supabase-js v2.0.5. I'm just not sure how the maintainers want to fix it (rollback a change, or re-write the code to work differently). PR #482 Tagging a few peeps, as a heads-up and to double-check my theory. @hf @david-plugge @thorwebdev Lets say you've set your JWT to expire in 240 seconds.
In the There are three things as part of the
|
If PR #482 is helping to resolve other issues, and is desirable to keep, then one solution to the current issue is to only call private _startAutoRefreshToken(value: number) {
if (this.refreshTokenTimer) clearTimeout(this.refreshTokenTimer)
if (value <= 0 || !this.autoRefreshToken) return
this.refreshTokenTimer = setTimeout(async () => {
this.networkRetries++
const {
data: { session },
error
} = await this.getSession()
if (!error && session) {
this.networkRetries = 0
}
if (
error instanceof AuthRetryableFetchError &&
this.networkRetries < NETWORK_FAILURE.MAX_RETRIES
)
this._startAutoRefreshToken(NETWORK_FAILURE.RETRY_INTERVAL ** this.networkRetries * 100) // exponential backoff
}, value)
if (typeof this.refreshTokenTimer.unref === 'function') this.refreshTokenTimer.unref()
} Rather than the current code: private _startAutoRefreshToken(value: number) {
if (this.refreshTokenTimer) clearTimeout(this.refreshTokenTimer)
if (value <= 0 || !this.autoRefreshToken) return
this.refreshTokenTimer = setTimeout(async () => {
this.networkRetries++
const {
data: { session },
error: sessionError,
} = await this.getSession()
if (!sessionError && session) {
const { error } = await this._callRefreshToken(session.refresh_token)
if (!error) this.networkRetries = 0
if (
error instanceof AuthRetryableFetchError &&
this.networkRetries < NETWORK_FAILURE.MAX_RETRIES
)
this._startAutoRefreshToken(NETWORK_FAILURE.RETRY_INTERVAL ** this.networkRetries * 100) // exponential backoff
}
}, value)
if (typeof this.refreshTokenTimer.unref === 'function') this.refreshTokenTimer.unref()
} |
This is probably going to get resolved with #564. |
I believe this already got resolved. The ticket has just remained open. |
Bug report
Describe the bug
Supabase-js 2.0.5 is generating 2 refresh requests for every refresh timer cycle. This is with supabase-js, javascript only.
Reverting to 2.0.4 goes back to one request.
Another user is seeing similar multiple refreshes with auth-helpers in nextjs with 2.0.5 and getting refresh token reuse errors after awhile. Discord discussion 1/2 way and below of user Karbust's related issue: https://discord.com/channels/839993398554656828/1038545959640117289
To Reproduce
Run supabase-js with a logged in user and onAuthStateChange (optional as network tab shows same issue).
Expected behavior
One refresh request per gotrue-js refresh cycle.
Screenshots
2.0.5 console.logs with 60 second jwt expire. (note 120 seconds does same thing)
2.0.4 console.logs
2.0.5 network tab:
System information
Supabase-js 2.0.5
Multiple browsers
Javascript standalone and Nextjs with auth-helpers.
Additional context
Add any other context about the problem here.
The text was updated successfully, but these errors were encountered: