Skip to content

Commit

Permalink
Using AuthorizeRouteView
Browse files Browse the repository at this point in the history
  • Loading branch information
JByfordRew committed Apr 4, 2022
1 parent 3aa2c68 commit 2a71df6
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 12 deletions.
Original file line number Diff line number Diff line change
@@ -1,18 +1,14 @@
<CascadingAuthenticationState>
<Router AppAssembly="@typeof(App).Assembly">
<Found Context="routeData">
<AuthorizeRouteView RouteData="@routeData" DefaultLayout="@typeof(MainLayout)">
<NotAuthorized>
@if (context.User.Identity?.IsAuthenticated != true)
{
<RedirectToLogin />
}
else
{
<p role="alert">You are not authorized to access this resource.</p>
}
</NotAuthorized>
</AuthorizeRouteView>
<LayoutView Layout="@typeof(MainLayout)">
<TransitionableRoutePrimary RouteData="@routeData" ForgetStateOnTransition="true">
<MyAuthorizeRouteView DefaultLayout="@typeof(MyViewLayout)" />
</TransitionableRoutePrimary>
<TransitionableRouteSecondary RouteData="@routeData" ForgetStateOnTransition="true">
<MyAuthorizeRouteView DefaultLayout="@typeof(MyViewLayout)" />
</TransitionableRouteSecondary>
</LayoutView>
<FocusOnNavigate RouteData="@routeData" Selector="h1" />
</Found>
<NotFound>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
@if (Transition?.RouteData != null)
{
<CascadingValue Value="Transition">
<AuthorizeRouteView RouteData="@Transition.RouteData" DefaultLayout="@DefaultLayout">
<NotAuthorized>
@if (context.User.Identity?.IsAuthenticated != true)
{
<RedirectToLogin />
}
else
{
<p role="alert">You are not authorized to access this resource.</p>
}
</NotAuthorized>
</AuthorizeRouteView>
</CascadingValue>
}

@code {
[CascadingParameter]
public Transition Transition { get; set; }

[Parameter]
public Type DefaultLayout { get; set; }
}

0 comments on commit 2a71df6

Please sign in to comment.