WBS-11 BFF Hardening: Implement auth caching state provider for instant sidebar transitions, forward proxy authentication cookies, and resolve WASM server-side prerendering BaseAddress null exception
WBS-9.3 - NULL Policy CI Gate / NULL Policy Validation (push) Failing after 8s
Quant Engine CI/CD Pipeline / validate-core (push) Failing after 14s
Quant Engine CI/CD Pipeline / validate-ui-and-storage (push) Has been skipped
Deploy to Production / Build & Deploy to Production (push) Failing after 3m7s
WBS-9.3 - NULL Policy CI Gate / NULL Policy Validation (push) Failing after 8s
Quant Engine CI/CD Pipeline / validate-core (push) Failing after 14s
Quant Engine CI/CD Pipeline / validate-ui-and-storage (push) Has been skipped
Deploy to Production / Build & Deploy to Production (push) Failing after 3m7s
This commit is contained in:
+21
-5
@@ -16,6 +16,8 @@ namespace QuantEngine.Web.Client.Infrastructure
|
||||
private const string RoleKey = "quant_admin_role";
|
||||
private const string RememberUsernameKey = "quant_admin_remember_username";
|
||||
|
||||
private AuthenticationState? _cachedState;
|
||||
|
||||
public CustomAuthenticationStateProvider(LocalStorageService localStorage, HttpClient http, IJSRuntime jsRuntime)
|
||||
{
|
||||
_localStorage = localStorage;
|
||||
@@ -25,6 +27,12 @@ namespace QuantEngine.Web.Client.Infrastructure
|
||||
|
||||
public override async Task<AuthenticationState> GetAuthenticationStateAsync()
|
||||
{
|
||||
if (_cachedState != null && _cachedState.User.Identity?.IsAuthenticated == true)
|
||||
{
|
||||
Console.WriteLine("[Auth] Returning cached authentication state");
|
||||
return _cachedState;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
Console.WriteLine("[Auth] GetAuthenticationStateAsync called");
|
||||
@@ -62,7 +70,9 @@ namespace QuantEngine.Web.Client.Infrastructure
|
||||
new Claim(ClaimTypes.Role, role ?? "Admin")
|
||||
}, "QuantAdminAuth");
|
||||
|
||||
return new AuthenticationState(new ClaimsPrincipal(identity));
|
||||
var state = new AuthenticationState(new ClaimsPrincipal(identity));
|
||||
_cachedState = state;
|
||||
return state;
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -106,7 +116,9 @@ namespace QuantEngine.Web.Client.Infrastructure
|
||||
new Claim(ClaimTypes.Role, role ?? "Admin")
|
||||
}, "QuantAdminAuth");
|
||||
|
||||
return new AuthenticationState(new ClaimsPrincipal(identity));
|
||||
var state = new AuthenticationState(new ClaimsPrincipal(identity));
|
||||
_cachedState = state;
|
||||
return state;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -122,7 +134,8 @@ namespace QuantEngine.Web.Client.Infrastructure
|
||||
Console.WriteLine($"[Auth] Unexpected error: {ex.Message}");
|
||||
}
|
||||
|
||||
return new AuthenticationState(_anonymous);
|
||||
_cachedState = new AuthenticationState(_anonymous);
|
||||
return _cachedState;
|
||||
}
|
||||
|
||||
public async Task MarkUserAsAuthenticatedAsync(string username, string accessToken, string role)
|
||||
@@ -152,7 +165,9 @@ namespace QuantEngine.Web.Client.Infrastructure
|
||||
}, "QuantAdminAuth");
|
||||
|
||||
var user = new ClaimsPrincipal(identity);
|
||||
NotifyAuthenticationStateChanged(Task.FromResult(new AuthenticationState(user)));
|
||||
var state = new AuthenticationState(user);
|
||||
_cachedState = state;
|
||||
NotifyAuthenticationStateChanged(Task.FromResult(state));
|
||||
}
|
||||
|
||||
public async Task MarkUserAsLoggedOutAsync()
|
||||
@@ -164,7 +179,8 @@ namespace QuantEngine.Web.Client.Infrastructure
|
||||
{
|
||||
await _localStorage.DeleteAsync(UsernameKey);
|
||||
}
|
||||
NotifyAuthenticationStateChanged(Task.FromResult(new AuthenticationState(_anonymous)));
|
||||
_cachedState = new AuthenticationState(_anonymous);
|
||||
NotifyAuthenticationStateChanged(Task.FromResult(_cachedState));
|
||||
}
|
||||
|
||||
public async Task LogoutFromServerAsync()
|
||||
|
||||
Reference in New Issue
Block a user