Using Authentication State in Blazor Components



I’m attempting to integrate AuthenticationState with Blazored.Modal.

There are no documents available that demonstrate the process of merging the two attributes/keys in the App.Razor file.

This is my present App.Razor configuration.

                        @if (!context.User.Identity.IsAuthenticated)

I’m trying to find the right place to insert


but I’m not sure where it should go. I attempted to place it below, but that caused duplicate page renders. I also experimented with enclosing the code above with CascadingBlazoredModal and placing CascadingBlazoredModal within the AuthenticationState.

I’m not finding the specific documentation I need, as the information available pertains only to CascadingValues/Params.

Any help would be appreciate it!

Thank you!

Solution 1:

According to the documentation, this should work even though I have not tested it.


Your modal hosted forms should allow you to retrieve the value that has been cascaded.

[CascadingParameter] public Task AuthTask { get; set; }

Solution 2:

I managed to make it function! Although I am uncertain if it is the most suitable choice…

To accomplish the task, I wrapped




and integrated authentication state into



Without enclosing the entire




, my access would be restricted to only the authenticated page of the application, leaving me unable to access the entire app.


Frequently Asked Questions

Posted in Uncategorized