Login with RefreshToken Crashes #48
-
Trying to log in with a Stored RefreshToken. var oldSessionStr = await DataLocal.PersistentData.UserSessionJson.GetValueAsync();
var oldSession = JsonConvert.DeserializeObject<Session>(oldSessionStr);
Client.Auth.SetAuth(oldSession.AccessToken);
var result = await Client.Auth.SignIn(Constants.SignInType.RefreshToken, oldSession.RefreshToken); Expected Outcome: Return anything, even an exception. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 2 replies
-
@ConnorIllingworth the method you're using to authenticate should work... at least provided the token is still valid! You could call However, you might want to look at providing a SessionHandler to the supabase client - it will handle all of this for you! For example:
var options = new SupabaseOptions
{
AutoRefreshToken = true,
AutoConnectRealtime = true,
SessionHandler = new SupabaseSessionHandler()
};
var client = new Supabase.Client(supabaseUrl, supabaseKey, options);
await supabase.InitializeAsync(); // <-- Will retrieve saved session and set it accordingly.
internal class SupabaseSessionHandler : ISupabaseSessionHandler
{
private string cacheKey = ".supabase.session";
private string appDataDir = FileSystem.Current.AppDataDirectory;
private string cachePath => Path.Combine(appDataDir, cacheKey);
public Task<bool> SessionDestroyer()
{
if (File.Exists(cachePath))
File.Delete(cachePath);
return Task.FromResult(true);
}
public async Task<bool> SessionPersistor<TSession>(TSession session) where TSession : Session
{
try
{
await File.WriteAllTextAsync(cachePath, JsonConvert.SerializeObject(session));
return true;
}
catch
{
return false;
}
}
public async Task<TSession?> SessionRetriever<TSession>() where TSession : Session
{
if (!File.Exists(cachePath)) return null;
var cache = await File.ReadAllTextAsync(cachePath);
if (!string.IsNullOrEmpty(cache))
{
return JsonConvert.DeserializeObject<TSession>(cache);
}
return null;
}
} |
Beta Was this translation helpful? Give feedback.
@ConnorIllingworth the method you're using to authenticate should work... at least provided the token is still valid! You could call
Client.Auth.GetUser(token)
to verify that the token is still valid (returns a user without exception).However, you might want to look at providing a SessionHandler to the supabase client - it will handle all of this for you!
For example:
Main.cs
Supab…