Added components, authentication and authorization
This commit is contained in:
@@ -0,0 +1,28 @@
|
||||
using Htmx.ApiDemo.Data;
|
||||
using Immediate.Apis.Shared;
|
||||
using Immediate.Handlers.Shared;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
|
||||
namespace Htmx.ApiDemo.Templates;
|
||||
|
||||
[Handler]
|
||||
[MapPost("/logout")]
|
||||
public static partial class PostLogoutHandler
|
||||
{
|
||||
// Empty command — [AsParameters] ensures form content-type is accepted
|
||||
// and antiforgery token in the form is validated by the middleware.
|
||||
public record Command;
|
||||
|
||||
private static async ValueTask HandleAsync(
|
||||
[AsParameters] Command _,
|
||||
AuthService authService,
|
||||
IHttpContextAccessor httpContextAccessor,
|
||||
CancellationToken token)
|
||||
{
|
||||
await authService.SignOutAsync();
|
||||
|
||||
var ctx = httpContextAccessor.HttpContext
|
||||
?? throw new InvalidOperationException("HttpContext is not available.");
|
||||
ctx.Response.Redirect("/login");
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user