How do I set login expiration
Opened this issue · 1 comments
LingDian2019 commented
When logging in to obtain an authToken, you need to set the Blazor login expiration based on the authToken.AuthToken is invalid, login must also fail, need to automatically jump to the login interface, login again.How to deal with this? Thank you for your answer!
vankampenp commented
@LingDian2019
Change app razor to include a redirect (this is standard in the newer templates)
<CascadingAuthenticationState>
<Router AppAssembly="@typeof(Program).Assembly" PreferExactMatches="@true">
<Found Context="routeData">
<AuthorizeRouteView RouteData="@routeData" DefaultLayout="@typeof(MainLayout)">
<NotAuthorized>
@if (!context.User.Identity.IsAuthenticated)
{
<RedirectToLogin />
}
else
{
<p>You are not authorized to access this resource.</p>
}
</NotAuthorized>
</AuthorizeRouteView>
</Found>
<NotFound>
<LayoutView Layout="@typeof(MainLayout)">
<p>Sorry, there's nothing at this address.</p>
</LayoutView>
</NotFound>
</Router>
</CascadingAuthenticationState>
Change or add the RedirectToLogin component to go to the login:
@inject NavigationManager Navigation
@code {
protected override void OnInitialized()
{
Navigation.NavigateTo("login");
}
}