Centralize admin auth with endpoint filter
This commit is contained in:
@@ -11,10 +11,10 @@ internal static class EndpointHelpers
|
||||
{
|
||||
public static async Task<Player?> GetAuthenticatedPlayer(HttpContext ctx, AppDbContext db)
|
||||
{
|
||||
if (ctx?.User?.Identity?.IsAuthenticated != true)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
if (ctx?.User?.Identity?.IsAuthenticated != true) return null;
|
||||
|
||||
if (ctx.Items.TryGetValue(nameof(Player), out var cached) && cached is Player cachedPlayer)
|
||||
return cachedPlayer;
|
||||
|
||||
var idValue = ctx.User.FindFirstValue(ClaimTypes.NameIdentifier);
|
||||
if (string.IsNullOrWhiteSpace(idValue) || !Guid.TryParse(idValue, out var playerId))
|
||||
@@ -28,7 +28,10 @@ internal static class EndpointHelpers
|
||||
if (existing is null)
|
||||
{
|
||||
await Infrastructure.PlayerIdentityExtensions.SignOutPlayerAsync(ctx);
|
||||
return null;
|
||||
}
|
||||
|
||||
ctx.Items[nameof(Player)] = existing;
|
||||
return existing;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user