Hello,
I’m using Auth0 in a Blazor WASM application. Everything works like I would expect, except the user is not redirected to their previous page after logging in. For example, if the user goes to the page: example.com/counter and clicks “Log In”, after they are logged in they are redirected to example.com instead of example.com/counter. This is a big issue, as it makes sending direct links to content on the site that requires authorization useless.
I had this issue in my main app and couldn’t solve it, so I started a new app based off of the Auth0 Blazor Wasm template. I removed the server portion (as I am using Wasm only), upgraded it to .NET 8.0, and changed the AccessControl.razor as follows:
@using Microsoft.AspNetCore.Components.Authorization
@using Microsoft.AspNetCore.Components.WebAssembly.Authentication
@using System.Diagnostics
@inject NavigationManager Navigation
@inject SignOutSessionStateManager SignOutManager
<AuthorizeView>
<Authorized>
Hello, @context.User.Identity.Name!
<a href="#" @onclick="BeginSignOut">Log out</a>
</Authorized>
<NotAuthorized>
<a href="#" @onclick="BeginSignIn">Log in</a>
</NotAuthorized>
</AuthorizeView>
@code{
private async Task BeginSignOut(MouseEventArgs args)
{
await SignOutManager.SetSignOutState();
Navigation.NavigateTo("authentication/logout");
}
private void BeginSignIn()
{
InteractiveRequestOptions requestOptions = new()
{
Interaction = InteractionType.SignIn,
ReturnUrl = Navigation.Uri,
};
Navigation.NavigateToLogin($"authentication/login", requestOptions);
}
}
The only significant change being using the InteractiveRequestOptions with a ReturnUrl that are required for .Net 7 and up.
This setup works (user is redirected after login correctly) when running and debugging on localhost, but as soon as I publish it anywhere (Azure Static Site, Azure App Service, Static Webhost, etc) I have the issue described above where I am not redirected properly.
Does anyone know what could be the issue?