added auth with a simple UI
This commit is contained in:
23
api/OED.Api/Infrastructure/Auth/SessionMiddleware.cs
Normal file
23
api/OED.Api/Infrastructure/Auth/SessionMiddleware.cs
Normal file
@@ -0,0 +1,23 @@
|
||||
using OED.Api.Core.Interfaces.Services;
|
||||
|
||||
namespace OED.Api.Infrastructure.Auth;
|
||||
|
||||
// Runs on every request — reads the session cookie and stamps CharacterId onto HttpContext.Items
|
||||
public class SessionMiddleware(RequestDelegate next)
|
||||
{
|
||||
public async Task InvokeAsync(HttpContext context, ISessionService sessionService)
|
||||
{
|
||||
if (context.Request.Cookies.TryGetValue("session", out var sessionId))
|
||||
{
|
||||
var session = await sessionService.GetAsync(sessionId);
|
||||
if (session is not null)
|
||||
{
|
||||
context.Items["CharacterId"] = session.CharacterId;
|
||||
context.Items["CharacterName"] = session.CharacterName;
|
||||
context.Items["Session"] = session;
|
||||
}
|
||||
}
|
||||
|
||||
await next(context);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user