Add username/password auth and login UI
This commit is contained in:
@@ -7,20 +7,15 @@ namespace GameList.Endpoints;
|
||||
|
||||
internal static class EndpointHelpers
|
||||
{
|
||||
public static async Task<Player> GetOrCreatePlayer(HttpContext ctx, AppDbContext db)
|
||||
public static async Task<Player?> GetAuthenticatedPlayer(HttpContext ctx, AppDbContext db)
|
||||
{
|
||||
if (!ctx.Items.TryGetValue(Infrastructure.PlayerIdentityExtensions.PlayerCookieName, out var value) || value is not Guid playerId)
|
||||
{
|
||||
throw new InvalidOperationException("Player cookie missing.");
|
||||
return null;
|
||||
}
|
||||
|
||||
var existing = await db.Players.FindAsync(playerId);
|
||||
if (existing != null) return existing;
|
||||
|
||||
var player = new Player { Id = playerId };
|
||||
db.Players.Add(player);
|
||||
await db.SaveChangesAsync();
|
||||
return player;
|
||||
return existing;
|
||||
}
|
||||
|
||||
public static async Task<Phase> GetPhase(AppDbContext db)
|
||||
|
||||
Reference in New Issue
Block a user