Skip to content

Commit

Permalink
Add redirect to login when visit wrong page
Browse files Browse the repository at this point in the history
  • Loading branch information
oveldman committed Jan 5, 2024
1 parent 6014052 commit 48a0b47
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
14 changes: 13 additions & 1 deletion MadWorld/MadWorld.Frontend.Admin/App.razor
Original file line number Diff line number Diff line change
@@ -1,9 +1,21 @@
@using MadWorld.Shared.Blazor
@using MadWorld.Shared.Blazor.Pages

<CascadingAuthenticationState>
<Router AppAssembly="@typeof(App).Assembly" AdditionalAssemblies="new []{ typeof(ISharedBlazorMarker).Assembly }">
<Found Context="routeData">
<RouteView RouteData="@routeData" DefaultLayout="@typeof(MainLayout)"/>
<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>
<FocusOnNavigate RouteData="@routeData" Selector="h1"/>
</Found>
<NotFound>
Expand Down
9 changes: 9 additions & 0 deletions MadWorld/MadWorld.Shared.Blazor/Pages/RedirectToLogin.razor
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
@using Microsoft.AspNetCore.Components.WebAssembly.Authentication
@inject NavigationManager Navigation

@code {
protected override void OnInitialized()
{
Navigation.NavigateToLogin("/Login");
}
}

0 comments on commit 48a0b47

Please sign in to comment.