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);