Files
hcs/Hcs.WebApp/Identity/IdentityComponentsEndpointRouteBuilderExtensions.cs

28 lines
884 B
C#

using Hcs.WebApp.Data;
using Microsoft.AspNetCore.Identity;
using Microsoft.AspNetCore.Mvc;
using System.Security.Claims;
namespace Hcs.WebApp.Identity
{
internal static class IdentityComponentsEndpointRouteBuilderExtensions
{
public static IEndpointConventionBuilder MapAdditionalIdentityEndpoints(this IEndpointRouteBuilder endpoints)
{
ArgumentNullException.ThrowIfNull(endpoints);
var accountGroup = endpoints.MapGroup("/account");
accountGroup.MapPost("/logout", async (
ClaimsPrincipal user,
SignInManager<AppUser> signInManager,
[FromForm] string returnUrl) =>
{
await signInManager.SignOutAsync();
return TypedResults.LocalRedirect($"~/{returnUrl}");
});
return accountGroup;
}
}
}