Secours de stockage sans etat d'authentification

This commit is contained in:
2026-04-13 23:30:05 +02:00
parent 7efdbc57a8
commit f4bdbf9e2b

View File

@@ -7,12 +7,17 @@ public sealed class UserSession(AuthenticationStateProvider authenticationStateP
{ {
public async ValueTask<UserStorageScope> GetStorageScopeAsync() public async ValueTask<UserStorageScope> GetStorageScopeAsync()
{ {
var authState = await authenticationStateProvider.GetAuthenticationStateAsync(); try
var userId = ResolveUserId(authState.User); {
var authState = await authenticationStateProvider.GetAuthenticationStateAsync();
var userId = ResolveUserId(authState.User);
return new UserStorageScope( return CreateStorageScope(userId);
$"{MatchStore.StorageKeyPrefix}:{userId}", }
$"{MatchStore.WindowNameKeyPrefix}:{userId}:"); catch
{
return CreateStorageScope("anonymous");
}
} }
private static string ResolveUserId(ClaimsPrincipal user) private static string ResolveUserId(ClaimsPrincipal user)
@@ -34,6 +39,11 @@ public sealed class UserSession(AuthenticationStateProvider authenticationStateP
return Uri.EscapeDataString(rawIdentifier.Trim()); 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); public readonly record struct UserStorageScope(string StorageKey, string WindowNameKey);