MudBlazor / Templates

Ready to use Blazor Templates in different styles and layout with all the basic setup already done for MudBlazor.
MIT License
745 stars 165 forks source link

Logout code not included. #450

Closed JanOlsmar closed 5 months ago

JanOlsmar commented 10 months ago

The logout code from Microsoft admin pages are not included. Template 0.6.5

(Had hoped for a Mud admin )

Unskilledcrab commented 9 months ago

+1

Unskilledcrab commented 9 months ago

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

kepham commented 7 months ago

`@implements IDisposable @inject NavigationManager NavigationManager

Home Counter Weather Auth Required @context.User.Identity?.Name
Register Login

@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`