dotnet-presentations / blazor-workshop

Blazor workshop
https://aka.ms/blazorworkshop
MIT License
3.5k stars 1.56k forks source link

app works in dev; error when trying to access appstate #369

Open rjean99 opened 10 months ago

rjean99 commented 10 months ago

Microsoft.AspNetCore.Authorization.DefaultAuthorizationService[2] Authorization failed. These requirements were not met: DenyAnonymousAuthorizationRequirement: Requires an authenticated user.

User can log in, but pizzas added before logging in are not restored and not re-directed to Checkout page

This is just happening from Azure, not in VS dev environment.

New to Blazor/.NET Core and not sure how to troubleshoot this.

https://blazingpizzaame.azurewebsites.net

rjean99 commented 10 months ago

This is probably related. When I click log out this message appears and doesn't ever go away:

Processing logout callback...

Now I'm thinking that "DenyAnonymousAuthorizationRequirement: Requires an authenticated user" message doesn't mean anything related to these issues because I do see this in my dev tools console when running in debug, too, but everything seems to function OK.

rjean99 commented 10 months ago

Backing up another step... Without a null check in RestorePizza, this error occurs in WASM. After adding a null check inside RestorePizza method, this error goes away but still have above behavior. So I can't tell if this is an appstate or authentication issue. And just to re-iterate, this only happens when running the deployment on Azure. Dev working OK. Maybe I'll try deploy to local IIS.

Unhandled exception rendering component: Arg_NullReferenceException System.NullReferenceException: Arg_NullReferenceException at BlazingPizza.Client.Pages.Authentication.RestorePizza(PizzaAuthenticationState pizzaState) at Microsoft.AspNetCore.Components.ComponentBase.CallStateHasChangedOnAsyncCompletion(Task task) at Microsoft.AspNetCore.Components.WebAssembly.Authentication.RemoteAuthenticatorViewCore1.<ProcessLogInCallback>d__86[[BlazingPizza.Client.PizzaAuthenticationState, BlazingPizza.Client, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null]].MoveNext() at Microsoft.AspNetCore.Components.WebAssembly.Authentication.RemoteAuthenticatorViewCore1.d__84[[BlazingPizza.Client.PizzaAuthenticationState, BlazingPizza.Client, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null]].MoveNext() at Microsoft.AspNetCore.Components.ComponentBase.CallStateHasChangedOnAsyncCompletion(Task task) at Microsoft.AspNetCore.Components.ComponentBase.RunInitAndSetParametersAsync() at Microsoft.AspNetCore.Components.RenderTree.Renderer.GetErrorHandledTask(Task , ComponentState )