Refactor app architecture and clean local artifacts
This commit is contained in:
@@ -0,0 +1,38 @@
|
||||
using Backend.Contracts;
|
||||
using Backend.Domain;
|
||||
using Backend.Services;
|
||||
|
||||
namespace Backend.Endpoints;
|
||||
|
||||
public static partial class AuthEndpoints
|
||||
{
|
||||
private static async Task<IResult> 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<IResult> 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);
|
||||
}
|
||||
Reference in New Issue
Block a user