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 sealed class UserSession(AuthenticationStateProvider authenticationStateProvider)
|
||||||
{
|
{
|
||||||
public async ValueTask<UserStorageScope> GetStorageScopeAsync()
|
public async ValueTask<UserStorageScope> GetStorageScopeAsync()
|
||||||
|
{
|
||||||
|
try
|
||||||
{
|
{
|
||||||
var authState = await authenticationStateProvider.GetAuthenticationStateAsync();
|
var authState = await authenticationStateProvider.GetAuthenticationStateAsync();
|
||||||
var userId = ResolveUserId(authState.User);
|
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);
|
||||||
|
|||||||
Reference in New Issue
Block a user