You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
The authenticated user get logout after a hour #33
Session being deleted when offline is a known issue of Supabase. Supabase lacks offline capability at the moment in general. We should implement a fix once it is fixed on js SDK, but until then, the use of this library should be with apps that you can safely assume your users are connected at all times.
Just run the simple
Login
Then force close the app
...
After 2 hours
Close your wifi or mobile data
Then open app again.
Issue is that
supabase.auth.currentUser is null after couples hours of having no internet connection
The library works as it should be. When you turn on the app again, the library will try to refresh user session if it's expired. If the device is offline, then refresh token will fail and user is log out.
@iampopal what's your expectation when the device is offline and user session is expired ?
Like
Whatsapp and Telegram or other social media apps
They never logout us when we get offline
The user session shall be saved and user shall not logout even the jwt expires
Reacted by Jakub Koffer, Ben Wunderlich, CodePoet, Chris Ward, Erick Heredia, Skjalg Holther, lseidman, Leandro Vallejos, Ralfarios, Murad Ruiz and 1 more
We see similar behaviour in production mode even when the app is open all the time.
It seems like the automatic token refresh is not happening.
Would it be possible to at least make the token refresh available via the API to let the client manually refresh the token when it is expired? Even better would be if the expire behaviour could be configured on the initialization.
We see similar behaviour in production mode even when the app is open all the time. It seems like the automatic token refresh is not happening.
Would it be possible to at least make the token refresh available via the API to let the client manually refresh the token when it is expired? Even better would be if the expire behaviour could be configured on the initialization.
I confirmed that when the app is running, Supabase automatically refreshes the token.
However, when the app is turned off and then expired, the session returns a null value.
I think the app should be turned on again and Supabase should process the process to get a new token, but this doesn't happen automatically.
I wonder what we think about this.
Additionally, If Supabase does not automatically receive a new token, I would like to know how to do this manually.
@KirioXX Thx for leaving comments. That's right. As you know, It's not a perfect solution. This is because if the user does not access the app for a long time, the method will fail. Better measures are needed for this. If anyone shares a good idea about this, it will help everyone. :)
Flutter app is used in a factory setting, Android and iOS devices
Devices are used 7am-4pm, then left on charge each night
During the day, the app is left idle 3 hours at most
The factory has decent Wifi, but not perfect
Summary
We find that out of 70 active devices, 1-2 get logged out each week since we deployed mid-January this year
It doesn't seem to correlate with the length of service (time elapsed since the device was first used) or idle time (time elapsed since the device was last used)
Examples
First occurrence:
Was found logged out at 4.10pm
The device was last used around 4.00pm to clock out at the end of shift
The device has been in service just over 7 days
Second occurrence:
Was reported as logged out at 2pm
Was last used at lunchtime when coming back from break at 12pm
The device had been in service 10 days
Third occurrence:
Device was reported logged out at 8:40am
Was last used at 7:00am that day
The device had been in service approx 9 days
Fourth occurrence:
Device was reported logged out at 9:31am
Was last used at 7:10am on the same day
The device had been in service 7 days
Whilst these all seem to be getting logged out at around 7-10 days of service, there are likely 40-50 devices that have NEVER been logged out in 80 days of service.
@christrunk@KirioXX Thank you for providing additional details on this issue. This issue is the next issue we will tackle, and we hope to ship a fix sometime next week. We apologize for the inconvenience we have caused.
Reacted by Ben Wunderlich, Chris Ward, Travis Jenkins, Casey Rogers and Abdurahman Popal
I'm getting this issue. However, in my case, neither user nor session are null. Was the above merged PR supposed to resolve this?
Here are my thoughts:
Supabase client should handle all this under the hood so I don't have to think about it
If there's a reason the client can't refresh the token, that should be reflected in the client's state so my app can catch it and handle it appropriately before attempting a failed server call. eg maybe add a hasValidToken flag to the auth client and call the auth state change callback whenever this flag changes.
void main() async {
WidgetsFlutterBinding.ensureInitialized();
await Supabase.initialize(
url: '<snipped for brevity>',
anonKey: '<snipped for brevity>',
);
print(Supabase.instance.client.auth.currentUser); // instance of 'User'
print(Supabase.instance.client.auth.currentSession); // instance of 'Session'
final dynamic result =
await Supabase.instance.client.from('profiles').select(); // crashes with jwt expired error
runApp(MyApp());
}
The error does not seem consistent. Just now I re-ran the above and it did not crash. Perhaps sometimes the client is failing to refresh the JWT token and other times it is not?
I've realized that this only happens on my emulator and only happens when the emulator time is out of sync and behind the real time so I'm presuming that's the issue!
Still experiencing the same issue! If the device goes to sleep for more than an hour (the access token expires), upon return the user will be logged out automatically. is really annoying UX for the user
Activity
bdlukaa commentedon Oct 5, 2021
did you
awaitwhen callingSupabase.initialize?iampopal commentedon Oct 7, 2021
Yes i do await
And my main function has async
iampopal commentedon Oct 7, 2021
This issue happens after couples hours of login when u not has internet
iampopal commentedon Oct 7, 2021
Please do a test with supabase quick start for flutter
Just run the simple
Login
Then force close the app
...
After 2 hours
Close your wifi or mobile data
Then open app again.
iampopal commentedon Oct 7, 2021
Issue is that
supabase.auth.currentUser is null after couples hours of having no internet connection
bdlukaa commentedon Oct 7, 2021
Is
supabase.auth.sessionalso null?dshukertjr commentedon Oct 8, 2021
Session being deleted when offline is a known issue of Supabase. Supabase lacks offline capability at the moment in general. We should implement a fix once it is fixed on js SDK, but until then, the use of this library should be with apps that you can safely assume your users are connected at all times.
supabase/auth-js#141 (comment)
phamhieu commentedon Oct 8, 2021
The library works as it should be. When you turn on the app again, the library will try to refresh user session if it's expired. If the device is offline, then refresh token will fail and user is log out.
@iampopal what's your expectation when the device is offline and user session is expired ?
phamhieu commentedon Oct 8, 2021
btw, default session expiry is in 1 hour. You can increase this value under auth settings
iampopal commentedon Oct 8, 2021
The JWT shall Expire as it normally do
But what I want is that after expiration of JWT
supabase.auth.currentUser
Shall not return null.
iampopal commentedon Oct 8, 2021
Like
Whatsapp and Telegram or other social media apps
They never logout us when we get offline
The user session shall be saved and user shall not logout even the jwt expires
KirioXX commentedon Jan 18, 2022
We see similar behaviour in production mode even when the app is open all the time.
It seems like the automatic token refresh is not happening.
Would it be possible to at least make the token refresh available via the API to let the client manually refresh the token when it is expired? Even better would be if the expire behaviour could be configured on the initialization.
iCodePoet commentedon Jan 25, 2022
I found the API.
But I don't know where to get the refresh token.
iCodePoet commentedon Jan 26, 2022
I confirmed that when the app is running, Supabase automatically refreshes the token.
However, when the app is turned off and then expired, the session returns a null value.
I think the app should be turned on again and Supabase should process the process to get a new token, but this doesn't happen automatically.
I wonder what we think about this.
Additionally, If Supabase does not automatically receive a new token, I would like to know how to do this manually.
1 remaining item
iCodePoet commentedon Jan 30, 2022
@KirioXX Thx for leaving comments. That's right. As you know, It's not a perfect solution. This is because if the user does not access the app for a long time, the method will fail. Better measures are needed for this. If anyone shares a good idea about this, it will help everyone. :)
christrunk commentedon Apr 19, 2022
Just to add our own experience here:
Scenario:
Summary
Examples
First occurrence:
Was found logged out at 4.10pm
The device was last used around 4.00pm to clock out at the end of shift
The device has been in service just over 7 days
Second occurrence:
Was reported as logged out at 2pm
Was last used at lunchtime when coming back from break at 12pm
The device had been in service 10 days
Third occurrence:
Device was reported logged out at 8:40am
Was last used at 7:00am that day
The device had been in service approx 9 days
Fourth occurrence:
Device was reported logged out at 9:31am
Was last used at 7:10am on the same day
The device had been in service 7 days
Whilst these all seem to be getting logged out at around 7-10 days of service, there are likely 40-50 devices that have NEVER been logged out in 80 days of service.
JWT is set to 1 week.
dshukertjr commentedon Apr 22, 2022
@christrunk @KirioXX Thank you for providing additional details on this issue. This issue is the next issue we will tackle, and we hope to ship a fix sometime next week. We apologize for the inconvenience we have caused.
caseycrogers commentedon Aug 9, 2022
I'm getting this issue. However, in my case, neither user nor session are null. Was the above merged PR supposed to resolve this?
Here are my thoughts:
hasValidTokenflag to the auth client and call the auth state change callback whenever this flag changes.bdlukaa commentedon Aug 9, 2022
@caseycrogers could you explain this?
caseycrogers commentedon Aug 9, 2022
The error does not seem consistent. Just now I re-ran the above and it did not crash. Perhaps sometimes the client is failing to refresh the JWT token and other times it is not?
bdlukaa commentedon Aug 9, 2022
It'd be awesome if you could post the crash error and stacktrace in here
caseycrogers commentedon Aug 9, 2022
Error:
PostgrestException(message: {"code":"PGRST301","details":null,"hint":null,"message":"JWT expired"}, code: 401, details: UnauthorStackTrace:
caseycrogers commentedon Aug 12, 2022
I've realized that this only happens on my emulator and only happens when the emulator time is out of sync and behind the real time so I'm presuming that's the issue!
dshukertjr commentedon Sep 30, 2022
I will close this issue as we have implemented a retry for when when the client is offline and fails to refresh the token.
zcmgyu commentedon Dec 14, 2024
After all, I decided to leave Supabase though my application went live already. :'(
khordoo commentedon May 23, 2025
Still experiencing the same issue! If the device goes to sleep for more than an hour (the access token expires), upon return the user will be logged out automatically. is really annoying UX for the user
Vinzent03 commentedon May 27, 2025
@khordoo This is a really old closed issue. Please open a new issue with more details about your situation by following the bug report template.