move user workload from siterouter to app component to improve performance and 404 handling

This commit is contained in:
sbwalker
2025-12-05 08:40:30 -05:00
parent 23d14c62a5
commit a51f87d743
12 changed files with 91 additions and 39 deletions

View File

@@ -158,13 +158,17 @@
// verify user is authenticated for current site
var authState = await AuthenticationStateProvider.GetAuthenticationStateAsync();
if (authState.User.Identity.IsAuthenticated
&& authState.User.Claims.Any(item => item.Type == Constants.SiteKeyClaimType && item.Value == SiteState.Alias.SiteKey)
&& PageState.StatusCode != (int)HttpStatusCode.NotFound)
if (authState.User.IsAuthenticated() && authState.User.SiteKey() == SiteState.Alias.SiteKey)
{
// get user
var userid = int.Parse(authState.User.Claims.First(item => item.Type == ClaimTypes.NameIdentifier).Value);
user = await UserService.GetUserAsync(userid, SiteState.Alias.SiteId);
if (PageState == null || PageState.User == null || PageState.User.UserId != authState.User.UserId())
{
// get user
user = await UserService.GetUserAsync(authState.User.UserId(), SiteState.Alias.SiteId);
}
else
{
user = PageState.User;
}
if (user != null)
{
user.IsAuthenticated = authState.User.Identity.IsAuthenticated;
@@ -339,7 +343,6 @@
IsInternalNavigation = _isInternalNavigation,
RenderId = renderid,
Refresh = false,
StatusCode = PageState?.StatusCode,
AllowCookies = _allowCookies.GetValueOrDefault(true)
};
OnStateChange?.Invoke(_pagestate);