Integrated AuthenticationStateProvider using .NET Core Identity
This commit is contained in:
@ -6,6 +6,7 @@
|
||||
@using Oqtane.Shared
|
||||
@using Microsoft.JSInterop
|
||||
@using Microsoft.AspNetCore.Components.Routing
|
||||
@inject AuthenticationStateProvider AuthenticationStateProvider
|
||||
@inject SiteState SiteState
|
||||
@inject IUriHelper UriHelper
|
||||
@inject INavigationInterception NavigationInterception
|
||||
@ -106,15 +107,13 @@ private async Task Refresh()
|
||||
}
|
||||
if (site != null || reload == true)
|
||||
{
|
||||
var interop = new Interop(jsRuntime);
|
||||
string userid = await interop.GetCookie("user");
|
||||
|
||||
user = null;
|
||||
if (PageState == null || reload == true)
|
||||
{
|
||||
if (!string.IsNullOrEmpty(userid))
|
||||
var authState = await AuthenticationStateProvider.GetAuthenticationStateAsync();
|
||||
if (authState.User.Identity.IsAuthenticated)
|
||||
{
|
||||
user = await UserService.GetUserAsync(int.Parse(userid));
|
||||
user = await UserService.GetCurrentUserAsync();
|
||||
}
|
||||
}
|
||||
else
|
||||
@ -122,23 +121,6 @@ private async Task Refresh()
|
||||
user = PageState.User;
|
||||
}
|
||||
|
||||
if (!string.IsNullOrEmpty(userid))
|
||||
{
|
||||
if (user != null && user.UserId != int.Parse(userid))
|
||||
{
|
||||
user = await UserService.GetUserAsync(int.Parse(userid));
|
||||
}
|
||||
// this is a hack for server-side Blazor where JSInterop is not working OnInit() which means the userid is not being retrieved from the cookie on the initial render and is not being loaded into PageState
|
||||
if (user == null)
|
||||
{
|
||||
user = await UserService.GetUserAsync(int.Parse(userid));
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
user = null;
|
||||
}
|
||||
|
||||
string path = new Uri(_absoluteUri).PathAndQuery.Substring(1);
|
||||
if (path.EndsWith("/")) { path = path.Substring(0, path.Length - 1); }
|
||||
if (alias.Path != "")
|
||||
|
Reference in New Issue
Block a user