1
0
mirror of https://github.com/akpaevj/onecmonitor.git synced 2026-06-15 21:32:34 +02:00
Files

20 lines
638 B
C#

using Microsoft.AspNetCore.Identity;
using OneSwiss.Server.Models;
namespace OneSwiss.Server.Components.Account;
internal sealed class IdentityUserAccessor(
UserManager<ApplicationUser> userManager,
IdentityRedirectManager redirectManager)
{
public async Task<ApplicationUser> GetRequiredUserAsync(HttpContext context)
{
var user = await userManager.GetUserAsync(context.User);
if (user is null)
redirectManager.RedirectToWithStatus("Account/InvalidUser",
$"Error: Unable to load user with ID '{userManager.GetUserId(context.User)}'.", context);
return user;
}
}