Closed davidchieregato closed 4 months ago
Morning @davidchieregato! Thanks for the report.
My initial reaction is that the application must be in the background during the normal interval that the gotrue-csharp client would normally refresh the token. The client itself does manage token refresh but it does so using a system timer. The thought being to make the token refresh as general as possible so-as to not be locked into a framework specific implementation. So, what I think is happening is that the timer is never being called to refresh the token because the application is in a suspended state.
What I would do in your case would be to check the gotrue token in your app resume lifecycle event and call Auth.RefreshSession()
or Auth.RefreshToken()
. This may be something you'd want to do periodically in the background too. You may also want to re-evaluate your token lifetime (set in the Supabase Admin panel).
Thoughts?
It's possible that the issue is related to how timers are managed when in background.
I just tried adding a resume event in my Application. I will report back if the issue arises or not within a few days, thanks for the hint!
protected override void OnResume()
{
base.OnResume();
Sup.Auth.RefreshSession();
}
Bug report
Describe the bug
The bug is quite difficult to reproduce because it appears rarely when resuming the application. I am using .net MAUI and the Exception is thrown to the application Main in native code. This exception will make the app crash but the autorenew of the token should be managed by the supabase-csharp library.
To Reproduce
Steps to reproduce the behavior, please provide code snippets or a repository:
I have a singleton class in MauiProgram.cs
My CustomSessionHandler is like this:
And I retrieve the service in the constructor in multiple places like this
public Utils(IServiceProvider service) { _supabaseClient = service.GetRequiredService(); }
Expected behavior
The library should renew the auth token.
Screenshots
NA
System information
Additional context
The stacktrace is as follows