2026-02-01 04:27:06 -06:00
|
|
|
namespace FiscalOS.API.Login;
|
|
|
|
|
|
|
|
|
|
internal static class Endpoint
|
|
|
|
|
{
|
|
|
|
|
private const string Route = "/login";
|
|
|
|
|
|
|
|
|
|
public static RouteHandlerBuilder MapLoginEndpoint(this WebApplication app)
|
|
|
|
|
{
|
|
|
|
|
return app.MapPost(Route, HandleAsync);
|
|
|
|
|
}
|
|
|
|
|
|
2026-02-01 08:07:23 -06:00
|
|
|
private static async Task<IResult> HandleAsync(
|
|
|
|
|
[FromBody] LoginRequest loginRequest,
|
|
|
|
|
[FromServices] AppDbContext appDbContext
|
|
|
|
|
)
|
2026-02-01 04:27:06 -06:00
|
|
|
{
|
2026-02-01 06:12:49 -06:00
|
|
|
// TODO: Implement actual auth flow
|
|
|
|
|
// 1. We want to make sure that
|
|
|
|
|
// the user exists
|
|
|
|
|
// 2. We want to make sure that
|
|
|
|
|
// tha the password is correct
|
|
|
|
|
// 3. We want to issue an access token
|
|
|
|
|
// with a refresh token
|
|
|
|
|
// 4. We want to store the refresh
|
|
|
|
|
// token
|
|
|
|
|
// 5. We want to set the refresh
|
|
|
|
|
// token in a cookie
|
|
|
|
|
|
|
|
|
|
// TODO: Things we need
|
|
|
|
|
// 1. We need a user model
|
|
|
|
|
// 2. We need a refresh token model
|
|
|
|
|
|
2026-02-01 08:07:23 -06:00
|
|
|
var user = await appDbContext.Users.SingleOrDefaultAsync(u => u.Username == loginRequest.Username);
|
|
|
|
|
|
|
|
|
|
if (user is null)
|
|
|
|
|
{
|
|
|
|
|
return Results.Unauthorized();
|
|
|
|
|
}
|
|
|
|
|
|
2026-02-01 04:27:06 -06:00
|
|
|
return Results.Ok();
|
|
|
|
|
}
|
|
|
|
|
}
|