You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When using <AuthorizeRouteView /> with authentication in Blazor Server, there's a significant limitation: we cannot specify a different layout for the NotAuthorized state.
I use <AuthorizeView> in my pages and two layouts:
<LoginLayout> for the login/logout pages.
<MainLayout> for all pages in the application
The Issue: Unauthorized users briefly see the authorized layout
During authentication verification, the DefaultLayout (usually MainLayout) is displayed momentarily. It is the AuthorizeRouteView / Authorizing call that displays “Authorizing...”.
[Router.razor]
<RouterAppAssembly="typeof(Program).Assembly">
<FoundContext="routeData">
<AuthorizeRouteViewRouteData="routeData"DefaultLayout="typeof(Layout.MainLayout)">
<Authorizing>
<span>Checking authorization...</span> @* hit during the login process *@
</Authorizing>
<NotAuthorized>
<span>Here is your wonderful component</span>
</NotAuthorized>
</AuthorizeRouteView>
<FocusOnNavigateRouteData="routeData"Selector="h1" />
</Found>
</Router>
[LoginPage.razor]
@page "/"@layout LoginLayout
...
This creates:
A visual "flash" of the wrong layout during login
If a have a code in OnAfterRender in MainLayout , it is executed once during the login process
Poor user experience with layout switching
Proposed Solution
Add a NotAuthorizedLayout parameter to AuthorizeRouteView:
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
Uh oh!
There was an error while loading. Please reload this page.
-
Problem Description
When using
<AuthorizeRouteView />
with authentication in Blazor Server, there's a significant limitation: we cannot specify a different layout for theNotAuthorized
state.I use
<AuthorizeView>
in my pages and two layouts:<LoginLayout>
for the login/logout pages.<MainLayout>
for all pages in the applicationThe Issue: Unauthorized users briefly see the authorized layout
During authentication verification, the
DefaultLayout
(usuallyMainLayout
) is displayed momentarily. It is the AuthorizeRouteView / Authorizing call that displays “Authorizing...”.[Router.razor]
[LoginPage.razor]
This creates:
OnAfterRender
inMainLayout
, it is executed once during the login processProposed Solution
Add a
NotAuthorizedLayout
parameter toAuthorizeRouteView
:This would allow:
@layout
directive to every pageRelated Issues
This problem was raised years ago in #39456 but only partial workarounds were suggested.
Current Workaround (Not Ideal)
The only "solution" currently is to:
LoginLayout
as the default in<Router>
@layout MainLayout
to every single page in the applicationThis is particularly problematic because:
MainLayout
(authenticated pages)LoginLayout
(login, register, forgot password)@layout MainLayout
to the majority of pages instead of just specifying@layout LoginLayout
on the few login-related pagesBeta Was this translation helpful? Give feedback.
All reactions