After implementing login logic, I want to redirect to ReturnUrl
if exists. The ReturnUrl
has Authorize
attribute, but when GetAuthenticationStateAsync()
is executed, protectedLocalStorage
is null after NavigationManager.NavigateTo()
is executed.
This is the relevant code for login
await protectedLocalStorage.SetAsync("authToken", token);
NavigationManager.NavigateTo(ReturnUrl ?? "");
And I’m trying to get protectedLocalStorage
at GetAuthenticationStateAsync()
like this
result = await protectedLocalStorage.GetAsync<string>("authToken"); //protectedLocalStorage is null after the redirect
I disabled the prerender at App.razor & it’s working fine except when trying to redirect to an authorized component
private IComponentRenderMode? RenderModeForPage => HttpContext.Request.Path.StartsWithSegments("/Account") ? null : new InteractiveServerRenderMode(prerender: false);
If I navigate to the authorized component normally by clicking on a link or typing the url -after login- it’s working properly. This is only happening after using NavigationManager.NavigateTo
function