question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Using AuthorizeView with Shell

See original GitHub issue

I’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:closed
  • Created 3 years ago
  • Comments:9 (9 by maintainers)

github_iconTop GitHub Comments

1reaction
Eiloncommented, Nov 3, 2020

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!

0reactions
Eiloncommented, Nov 10, 2020

Thank you so much @Dreamescaper for taking the initiative on this change and coming up with a terrific solution!

Read more comments on GitHub >

github_iconTop Results From Across the Web

Secure ASP.NET Core Blazor Server apps
Blazor Server apps are configured for security in the same manner as ASP. ... For guidance on the use of AuthorizeView, see ASP....
Read more >
Security: authentication and authorization in ASP.NET Web ...
The AuthorizeView component selectively displays UI depending on whether the user is authorized to see it. It also exposes a context variable ...
Read more >
Role Based Authorization In Blazor
In this post, we will see how to add authentication and role-based authorization using identity framework in Blazor application.
Read more >
How to make Navigation and Authorization Screen ? #188
AuthorizeView works normally. ... The ControlGallery sample in this repo shows how to use Shell along with the navigation feature to ...
Read more >
Authorization In Blazor WebAssembly
Here AuthorizeView component renders the users who matched with at least one role that is grouped under the policy. Roles Authorize Attribute To ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found