question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

autoRefreshToken doesn't work

See original GitHub issue

Bug report

Describe the bug

After initialising supabase client with

createClient(supabaseUrl, supabaseKey, {
  localStorage: AsyncStorage as any,
  autoRefreshToken: true
});

and setting the JWT expiry to 60 (seconds) on the supabase dashboard, the token does not refresh after 60 seconds have elapsed. Oddly enough, setting the JWT expiry to anything less than 60 triggers the token refresh but it constantly updates without waiting for expiry

To Reproduce

Steps to reproduce the behavior, please provide code snippets or a repository:

  1. Setup RN project (I used expo bare)
  2. Set JWT expiry to 60
  3. Add supabase auth state listener
  4. Sign in
  5. Wait for refresh token to update (doesn’t update)

Expected behavior

The token should refresh after the expiry time set on the supabase dashboard

System information

  • OS: macOS
  • Version of supabase-js: 1.11.14
  • Version of Node.js: 16.1.0

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:8 (2 by maintainers)

github_iconTop GitHub Comments

17reactions
b2m9commented, Dec 2, 2021

Sorry to dig out an old issue, but are we sure this is fixed? Despite initializing the Supabase client with autoRefreshToken: true I have to double check session.expires_at and initiate supabase.auth.refreshSession() manually throughout my app. (on version 1.28.2)

There isn’t much documentation on how autoRefreshToken is supposed to work. But judging from the questions in the discussions section, I’m not the only one who is having trouble letting Supabase refresh expired JWTs.

4reactions
churichardcommented, Jun 10, 2021

Having the same issue here. I’m constantly needing to log back into my app, even though I’ve set the expiration date to be a week long and have autoRefreshToken set to true. It seems like I need to re-enter my credentials even if the token is not actually expired (i.e. I need to re-enter my credentials even though a week has not passed since the last time I did it). This happens both on localhost and on my production website.

If autoRefreshToken is true, I would expect the token to be automatically refreshed without needing to enter my credentials again. In other words, if I’ve logged in once, I should stay logged in unless I’ve explicitly logged out or cleared my cookies/cache.

Read more comments on GitHub >

github_iconTop Results From Across the Web

What Are Refresh Tokens and How to Use Them Securely
Refresh tokens are bearer tokens. It's impossible for the authorization server to know who is legitimate or malicious when receiving a new ...
Read more >
Solved: When to refresh an access token? - 391930
Solved: Hi all, According to the docs, An access token, if not used, will expire in 24 hours. In addition, according to information...
Read more >
Should access tokens be refreshed automatically or manually?
Automatically Refreshing​​ For every request that requires authentication/authorization, the user will send both tokens on the request headers. ...
Read more >
Automatic refresh of Access Token doesn't work
I am "emedding for organization" and trying to use the automatic refresh of access token described here by providing eventHooks.
Read more >
OAuth 2.0 Refresh Token Best Practices - Fusebit
Learn the best practices you should consider for managing OAuth 2.0 refresh tokens and access to your app.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found