I created a new Blazor project with individual accounts, then transferred the files over to the existing project. Then renamed ApplicationDbContext to: IdentityContext to distinguish from the application context. Then ran the update database command with the existing migration for identity.
20 lines
634 B
C#
20 lines
634 B
C#
using Microsoft.AspNetCore.Identity;
|
|
using ServerManagement.Data;
|
|
|
|
namespace ServerManagement.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;
|
|
}
|
|
}
|