mirror of
https://github.com/fergalmoran/api.fergl.ie.git
synced 2025-12-22 09:18:23 +00:00
21 lines
618 B
C#
21 lines
618 B
C#
using Ferglie.Api.Data;
|
|
using Microsoft.AspNetCore.Identity;
|
|
|
|
namespace Ferglie.Api.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;
|
|
}
|
|
}
|
|
}
|