using Backend.Contracts; using Backend.Domain; using Backend.Services; namespace Backend.Endpoints; public static partial class AuthEndpoints { private static async Task GetSession(HttpContext context, IUserSessionService userSessionService) { var session = await userSessionService.ResolveSessionAsync(context, context.RequestAborted); if (session is null) { return Results.Unauthorized(); } return Results.Ok(ToAuthSessionDto(session)); } private static async Task Logout(HttpContext context, IUserSessionService userSessionService) { var session = await userSessionService.ResolveSessionAsync(context, context.RequestAborted); if (session is null) { return Results.Ok(new { loggedOut = true }); } await userSessionService.LogoutAsync(session, context.RequestAborted); return Results.Ok(new { loggedOut = true }); } private static AuthSessionDto ToAuthSessionDto(UserSession session) => new( session.SessionToken, session.TwitchUserId, session.DisplayName, session.Role); }