From f4bdbf9e2be6081ec5cbd4348db5565eb2659680 Mon Sep 17 00:00:00 2001 From: Christophe Date: Mon, 13 Apr 2026 23:30:05 +0200 Subject: [PATCH] Secours de stockage sans etat d'authentification --- ChessCubing.App/Services/UserSession.cs | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/ChessCubing.App/Services/UserSession.cs b/ChessCubing.App/Services/UserSession.cs index 19a66a5..42ada67 100644 --- a/ChessCubing.App/Services/UserSession.cs +++ b/ChessCubing.App/Services/UserSession.cs @@ -7,12 +7,17 @@ public sealed class UserSession(AuthenticationStateProvider authenticationStateP { public async ValueTask GetStorageScopeAsync() { - var authState = await authenticationStateProvider.GetAuthenticationStateAsync(); - var userId = ResolveUserId(authState.User); + try + { + var authState = await authenticationStateProvider.GetAuthenticationStateAsync(); + var userId = ResolveUserId(authState.User); - return new UserStorageScope( - $"{MatchStore.StorageKeyPrefix}:{userId}", - $"{MatchStore.WindowNameKeyPrefix}:{userId}:"); + return CreateStorageScope(userId); + } + catch + { + return CreateStorageScope("anonymous"); + } } private static string ResolveUserId(ClaimsPrincipal user) @@ -34,6 +39,11 @@ public sealed class UserSession(AuthenticationStateProvider authenticationStateP return Uri.EscapeDataString(rawIdentifier.Trim()); } + + private static UserStorageScope CreateStorageScope(string userId) + => new( + $"{MatchStore.StorageKeyPrefix}:{userId}", + $"{MatchStore.WindowNameKeyPrefix}:{userId}:"); } public readonly record struct UserStorageScope(string StorageKey, string WindowNameKey);