fullstackhero / blazor-wasm-boilerplate

Clean Architecture Boilerplate Template for .NET 6.0 Blazor WebAssembly built for FSH WebAPI with the goodness of MudBlazor Components.

Home Page:https://fullstackhero.net/blazor-webassembly-boilerplate/general/getting-started/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Why does the registration page keep redirecting to the login page as soon as button pressed ?

Chcoflex opened this issue · comments

commented

When I use the Register page, I would like to keep it there to display errors, such as duplicate email address. But for some reason, that I don't understand, it always, always, redirects to the login page as soon as the register button is pressed, regardless of the errors.

Any idea on how to keep it on page ?

commented

I tracked it down to the JwtAuthenticationHeaderHandler

I couldn't find a better way to avoid the GetAccessTokenAsync() other than to add a list of constants to avoid.

    protected override async Task<HttpResponseMessage> SendAsync(HttpRequestMessage request, CancellationToken cancellationToken)
    {
        // List of Anonymous API endpoints that should bypass token handling
        bool shouldBypassTokenHandling = BypassedEndpoints.Endpoints.Any(endpoint =>
        request.RequestUri?.AbsolutePath.Contains(endpoint, StringComparison.OrdinalIgnoreCase) == true);

        if (request.RequestUri?.AbsolutePath.Contains("/tokens") is not true && !shouldBypassTokenHandling)
        {
            if (await _tokenProviderAccessor.TokenProvider.GetAccessTokenAsync() is string token)
            {
                request.Headers.Authorization = new AuthenticationHeaderValue("Bearer", token);
            }
            else
            {
                _navigation.NavigateTo("/login");
            }
        }

        return await base.SendAsync(request, cancellationToken);
    }