Blazor WASM: logout when got 401, should i expect logout to be run when call #53777
-
the page has an attribute [Authorize] the app covered with CascadingAuthenticationState when I call an external API I intercept the response to check if it is 401, if so, raise an Unauthorized exception & catch it catch (UnauthorizedAccessException) I expected the Blazor to redirect to logout when
public override void Logout() and the user is not authenticated anymore, but nothing happens, should I use the navigation manager logout instead? |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments
-
is it ok to try to get AuthenticationStateProvider.AuthenticationStateChanged += AuthenticationStateProviderOnAuthenticationStateChanged; from @Inject AuthenticationStateProvider AuthenticationStateProvider ??? does not work, the service is scoped, but even having in app.razor protected override Task OnInitializedAsync()
} does not fire an event when i manually call _authenticationStateProvider.Logout(); |
Beta Was this translation helpful? Give feedback.
-
finally did through handler `public class CustomDelegatingHandler(NavigationManager navm, IConfiguration config) : DelegatingHandler
}` hope if i create control & place it to page & inject auth state service to the control, it will work, but needs to be checked |
Beta Was this translation helpful? Give feedback.
finally did through handler
`public class CustomDelegatingHandler(NavigationManager navm, IConfiguration config) : DelegatingHandler
{
protected override async Task SendAsync(HttpRequestMessage request, CancellationToken cancellationToken)
{
request.SetBrowserRequestCredentials(BrowserRequestCredentials.Include);
var response = await base.SendAsync(request, cancellationToken);
if (response.StatusCode == HttpStatusCode.Unauthorized)
{
Console.WriteLine("CustomDelegatingHandler | SendAsync | HttpStatusCode.Unauthorized");
}`
hope if i create control & place it to page & inject auth state service to the cont…