I am trying to build a blazor wasm app and trying to authenticate with Jwt token. I am facing with an interesting problem. When I login, I can't access the pages which has [Authorize] attributes. But after refreshing the page, authentication works. Where may be the issue?
2
votes
1 Answers
0
votes
I have figured out the problem. While you are doing login operations you need to force load. If you don't force load AuthenticationStateProvider is not refreshed.
async Task Login()
{
var token = await AuthenticationUseCases.LoginAsync(userViewModel.UserName, userViewModel.Password);
if (string.IsNullOrWhiteSpace(token))
{
NotificationMessage message = new NotificationMessage { Severity = NotificationSeverity.Error, Summary = "Info Summary", Detail = "Info Detail", Duration = 4000 };
NotificationService.Notify(message);
}
else
NavigationManager.NavigateTo("/", true); //true means force load
}