21 lines
686 B
C#
21 lines
686 B
C#
using OpenArchival.DataAccess;
|
|
using Microsoft.AspNetCore.Identity;
|
|
|
|
namespace MyAppName.WebApp.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;
|
|
}
|
|
}
|
|
}
|