From d9f9cf16c57eb0653234336000255b58c34ddba6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Joa=CC=83o=20Neves?= Date: Sat, 26 Oct 2024 10:40:49 +0100 Subject: [PATCH] Introduce LoadSessionAsync for async scenarios --- Gotrue/Client.cs | 11 +++++++++-- Gotrue/Gotrue.csproj | 4 ++-- Gotrue/Interfaces/IGotrueClient.cs | 6 ++++++ Gotrue/Interfaces/IGotrueSessionPersistence.cs | 10 ++++++++++ GotrueTests/AnonKeyClientTests.cs | 2 +- README.md | 2 +- 6 files changed, 29 insertions(+), 6 deletions(-) diff --git a/Gotrue/Client.cs b/Gotrue/Client.cs index 544ceeb4..0abe9802 100644 --- a/Gotrue/Client.cs +++ b/Gotrue/Client.cs @@ -68,7 +68,7 @@ public class Client : IGotrueClient /// /// /// var client = new Supabase.Gotrue.Client(options); - /// client.LoadSession(); + /// await client.LoadSessionAsync(); /// await client.RetrieveSessionAsync(); /// /// @@ -725,12 +725,19 @@ public async Task RefreshToken() NotifyAuthStateChange(TokenRefreshed); } - /// + [Obsolete("Call LoadSessionAsync instead.")] public void LoadSession() { if (_sessionPersistence != null) UpdateSession(_sessionPersistence.Persistence.LoadSession()); } + + /// + public async Task LoadSessionAsync() + { + if (_sessionPersistence != null) + UpdateSession(await _sessionPersistence.Persistence.LoadSessionAsync()); + } /// diff --git a/Gotrue/Gotrue.csproj b/Gotrue/Gotrue.csproj index 8d152266..5639d05a 100644 --- a/Gotrue/Gotrue.csproj +++ b/Gotrue/Gotrue.csproj @@ -16,8 +16,8 @@ https://avatars.githubusercontent.com/u/54469796?s=200&v=4 https://github.com/supabase-community/gotrue-csharp supabase, gotrue - 6.0.3 - 6.0.3 + 6.0.4 + 6.0.4 https://github.com/supabase-community/gotrue-csharp git icon.png diff --git a/Gotrue/Interfaces/IGotrueClient.cs b/Gotrue/Interfaces/IGotrueClient.cs index 3b74aff0..1d617bfc 100644 --- a/Gotrue/Interfaces/IGotrueClient.cs +++ b/Gotrue/Interfaces/IGotrueClient.cs @@ -424,8 +424,14 @@ public interface IGotrueClient : IGettableHeaders /// /// Loads the session from the persistence layer. /// + [Obsolete("Use LoadSessionAsync")] void LoadSession(); + /// + /// Loads the session asynchronously from the persistence layer. + /// + Task LoadSessionAsync(); + /// /// Retrieves the settings from the server /// diff --git a/Gotrue/Interfaces/IGotrueSessionPersistence.cs b/Gotrue/Interfaces/IGotrueSessionPersistence.cs index cd500dfe..2145a629 100644 --- a/Gotrue/Interfaces/IGotrueSessionPersistence.cs +++ b/Gotrue/Interfaces/IGotrueSessionPersistence.cs @@ -1,3 +1,6 @@ +using System; +using System.Threading.Tasks; + namespace Supabase.Gotrue.Interfaces { /// @@ -23,6 +26,13 @@ public interface IGotrueSessionPersistence /// Loads the session from the persistence implementation. Returns null if there is no session. /// /// + [Obsolete("Use LoadSessionAsync instead")] public TSession? LoadSession(); + + /// + /// Loads the session asynchronously from the persistence implementation. Returns null if there is no session. + /// + /// + public Task LoadSessionAsync() => Task.FromResult(LoadSession()); } } diff --git a/GotrueTests/AnonKeyClientTests.cs b/GotrueTests/AnonKeyClientTests.cs index 784fec00..cde5ae8c 100644 --- a/GotrueTests/AnonKeyClientTests.cs +++ b/GotrueTests/AnonKeyClientTests.cs @@ -95,7 +95,7 @@ public async Task SaveAndLoadUser() newClient.AddStateChangedListener(AuthStateListener); // Loads the session from storage - newClient.LoadSession(); + await newClient.LoadSessionAsync(); Contains(_stateChanges, SignedIn); AreEqual(newClient.CurrentSession, newPersistence.SavedSession); diff --git a/README.md b/README.md index 8f878ec6..123591cb 100644 --- a/README.md +++ b/README.md @@ -170,7 +170,7 @@ async void Initialize() { client.AddStateChangedListener(AuthStateListener); // Load the session from persistence - client.LoadSession(); + await client.LoadSessionAsync(); // Loads the session using SessionRetriever and sets state internally. await client.RetrieveSessionAsync(); }