29 lines
843 B
C#
29 lines
843 B
C#
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 class 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");
|
|
}
|
|
}
|