I am trying to implement JWT auth on a Blazor App 9 (using Server interactivity) but I can't seem to get app to route to the Login page when the user first starts the app. The Index has an [Authorize] attribute and when i run the app i get a "Page isn't working right now, error 401" instead of redirecting me to the Login page. Going to an unsecured page before trying to navigate to index works.Here is my Routes code
<Router AppAssembly="@typeof(Program).Assembly"><Found Context="routeData"><AuthorizeRouteView RouteData="@routeData" DefaultLayout="@typeof(MainLayout)"><NotAuthorized><RedirectToLogin /></NotAuthorized></AuthorizeRouteView></Found><NotFound><LayoutView Layout="@typeof(MainLayout)"><p>Sorry, there's nothing at this address.</p></LayoutView></NotFound>I have also added the following code to try to force it but the OnIntitializedAsync function isn't even being called.
protected override async Task OnInitializedAsync(){ var authState = await AuthStateProvider.GetAuthenticationStateAsync(); if (!authState.User.Identity.IsAuthenticated) { NavigationManager.NavigateTo("login"); }}The component has a simple navigation manager on the init function that routes to /login.
It seems that I have to re-learn blazor after every update.
Edit 1I am using the builder.Services.AddCascadingAuthenticationState(); in the Program file instead of the surrounding the Router