Explain the role of the AuthenticationStateProvider. How does it notify the UI that the user's auth status has changed?
Last updated
AuthenticationStateProvideris the single source of truth for the current user, consumed byAuthorizeView,CascadingAuthenticationStateand[Authorize].On login/logout it calls
NotifyAuthenticationStateChangedwith a newTask<AuthenticationState>, raising theAuthenticationStateChangedevent.CascadingAuthenticationStatelistens and re-cascades the new state, re-rendering dependent components. Custom providers (common in WASM) subclass it and call the notify method.
- https://learn.microsoft.com/en-us/aspnet/core/blazor/security/authentication-state?view=aspnetcore-10.0
- https://medium.com/careerbytecode/i-changed-the-users-role-but-blazor-didn-t-care-until-i-did-this-one-thing-bfc16fa708bd
- https://www.youtube.com/watch?v=iq2btD9WufI
- https://dev.to/auth0/securing-blazor-in-all-its-flavors-2819