Secours de stockage sans etat d'authentification
This commit is contained in:
@@ -6,13 +6,18 @@ namespace ChessCubing.App.Services;
|
||||
public sealed class UserSession(AuthenticationStateProvider authenticationStateProvider)
|
||||
{
|
||||
public async ValueTask<UserStorageScope> GetStorageScopeAsync()
|
||||
{
|
||||
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);
|
||||
|
||||
Reference in New Issue
Block a user