Using AuthorizeView with Shell
See original GitHub issueI’m trying to use asp net core auth with Mobile Blazor (by registering custom AuthenticationStateProvider and storing jwt token in SecureStorage) and use AuthorizedView component. So I want to show login page when user is not authenticated, so I’m trying to do something like that:
<CascadingAuthenticationState>
<Shell>
<AuthorizeView>
<Authorized>
<TabBar>
<Tab Icon="Icons.Home">
<HomePage />
</Tab>
<Tab Icon="Icons.Person">
<ProfilePage />
</Tab>
</TabBar>
</Authorized>
<NotAuthorized>
<TabBar>
<Mobile.Pages.LoginPage />
</TabBar>
</NotAuthorized>
</AuthorizeView>
</Shell>
</CascadingAuthenticationState>
And it basically works - with the exception of refreshing when state changes. So if I log in or log out, I have to reopen the app to see updated results.
I’ve tried injecting AuthenticationStateProvider, and invoke StateHasChanged explicitly on AuthenticationStateChanged event, but that has no effect.
I’ve also tried to put AuthorizedView inside TabBar:
<TabBar>
<AuthorizeView>
<Authorized>
<Tab Icon="Icons.Home">
<HomePage />
</Tab>
<Tab Icon="Icons.Person">
<ProfilePage />
</Tab>
</Authorized>
<NotAuthorized>
<Tab>
<Mobile.Pages.LoginPage />
</Tab>
</NotAuthorized>
</AuthorizeView>
</TabBar>
This way I can see at least some updates - new tabs are added, but never removed from Shell (so I see login page as separate tab after logout).
Is there anything I do wrong here? Thanks!
Issue Analytics
- State:
- Created 3 years ago
- Comments:9 (9 by maintainers)

Top Related StackOverflow Question
Oh this is cool! (Even though it isn’t working 😄 )
I’m guessing this involves some UI update scenarios that might not be fully implemented yet. I am now vaguely recalling that maybe the Shell wrapper doesn’t support removing tabs (the real Shell in Xamarin.Forms should).
I’ll take a look, hopefully an easy fix!
Thank you so much @Dreamescaper for taking the initiative on this change and coming up with a terrific solution!