Closed JanOlsmar closed 5 months ago
+1
Solved by add the following to Components -> Account -> Pages
@page "/Account/Logout"
@using Microsoft.AspNetCore.Identity
@inject SignInManager<ApplicationUser> SignInManager
@inject NavigationManager NavigationManager
@code {
protected override async Task OnInitializedAsync()
{
await SignInManager.SignOutAsync();
NavigationManager.NavigateTo("/");
}
}
And then you can logout a user from the app with the following:
<MudNavLink Href="Account/Logout" Match="NavLinkMatch.Prefix" Icon="@Icons.Material.Filled.ExitToApp">Logout</MudNavLink>
It's very basic and there's room for improvement but for someone just trying to get it working quickly, it functions well enough
`@implements IDisposable @inject NavigationManager NavigationManager
@code { private string? currentUrl;
protected override void OnInitialized()
{
currentUrl = NavigationManager.ToBaseRelativePath(NavigationManager.Uri);
NavigationManager.LocationChanged += OnLocationChanged;
}
private void OnLocationChanged(object? sender, LocationChangedEventArgs e)
{
currentUrl = NavigationManager.ToBaseRelativePath(e.Location);
StateHasChanged();
}
public void Dispose()
{
NavigationManager.LocationChanged -= OnLocationChanged;
}
}
This uses the same convention as the official Blazor Template`
The logout code from Microsoft admin pages are not included. Template 0.6.5
(Had hoped for a Mud admin )