unauthirozed login fix :)
All checks were successful
Build Docker Images / test (map[name:Morska plugin_project:DiunaBI.Plugins.Morska]) (push) Successful in 1m37s
Build Docker Images / test (map[name:PedrolloPL plugin_project:DiunaBI.Plugins.PedrolloPL]) (push) Successful in 1m28s
Build Docker Images / build-and-push (map[image_suffix:morska name:Morska plugin_project:DiunaBI.Plugins.Morska]) (push) Successful in 2m3s
Build Docker Images / build-and-push (map[image_suffix:pedrollopl name:PedrolloPL plugin_project:DiunaBI.Plugins.PedrolloPL]) (push) Successful in 1m44s
All checks were successful
Build Docker Images / test (map[name:Morska plugin_project:DiunaBI.Plugins.Morska]) (push) Successful in 1m37s
Build Docker Images / test (map[name:PedrolloPL plugin_project:DiunaBI.Plugins.PedrolloPL]) (push) Successful in 1m28s
Build Docker Images / build-and-push (map[image_suffix:morska name:Morska plugin_project:DiunaBI.Plugins.Morska]) (push) Successful in 2m3s
Build Docker Images / build-and-push (map[image_suffix:pedrollopl name:PedrolloPL plugin_project:DiunaBI.Plugins.PedrolloPL]) (push) Successful in 1m44s
This commit is contained in:
@@ -24,16 +24,43 @@ public class UnauthorizedResponseHandler : DelegatingHandler
|
|||||||
{
|
{
|
||||||
Console.WriteLine("⚠️ 401 Unauthorized response detected - clearing credentials and redirecting to login");
|
Console.WriteLine("⚠️ 401 Unauthorized response detected - clearing credentials and redirecting to login");
|
||||||
|
|
||||||
// Create a scope to get scoped services
|
try
|
||||||
using var scope = _serviceProvider.CreateScope();
|
{
|
||||||
var authService = scope.ServiceProvider.GetRequiredService<AuthService>();
|
// Create a scope to get scoped services
|
||||||
var navigationManager = scope.ServiceProvider.GetRequiredService<NavigationManager>();
|
using var scope = _serviceProvider.CreateScope();
|
||||||
|
var authService = scope.ServiceProvider.GetRequiredService<AuthService>();
|
||||||
|
var navigationManager = scope.ServiceProvider.GetRequiredService<NavigationManager>();
|
||||||
|
|
||||||
// Clear authentication
|
// Clear authentication
|
||||||
await authService.ClearAuthenticationAsync();
|
await authService.ClearAuthenticationAsync();
|
||||||
|
|
||||||
// Navigate to login page with session expired message
|
// Navigate to login page with session expired message
|
||||||
navigationManager.NavigateTo("/login?sessionExpired=true", forceLoad: true);
|
navigationManager.NavigateTo("/login?sessionExpired=true", forceLoad: true);
|
||||||
|
}
|
||||||
|
catch (InvalidOperationException ex)
|
||||||
|
{
|
||||||
|
// NavigationManager may not be initialized in all contexts (e.g., during initial load)
|
||||||
|
// Log the error and allow the 401 response to propagate to the caller
|
||||||
|
Console.WriteLine($"⚠️ Cannot navigate to login - NavigationManager not initialized: {ex.Message}");
|
||||||
|
Console.WriteLine("⚠️ 401 response will be handled by the calling component");
|
||||||
|
|
||||||
|
// Still try to clear authentication if we can get the AuthService
|
||||||
|
try
|
||||||
|
{
|
||||||
|
using var scope = _serviceProvider.CreateScope();
|
||||||
|
var authService = scope.ServiceProvider.GetRequiredService<AuthService>();
|
||||||
|
await authService.ClearAuthenticationAsync();
|
||||||
|
}
|
||||||
|
catch (Exception clearEx)
|
||||||
|
{
|
||||||
|
Console.WriteLine($"⚠️ Could not clear authentication: {clearEx.Message}");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
// Log any other unexpected errors
|
||||||
|
Console.WriteLine($"❌ Error handling 401 response: {ex.Message}");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return response;
|
return response;
|
||||||
|
|||||||
Reference in New Issue
Block a user