Skip to content

Commit

Permalink
Adds logout button (#30)
Browse files Browse the repository at this point in the history
* Logout button

* Simplify code
  • Loading branch information
A-Guldborg authored Mar 6, 2024
1 parent b2341a2 commit ef22c79
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 1 deletion.
6 changes: 6 additions & 0 deletions Shifty.App/Services/AuthenticationService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,5 +47,11 @@ public async Task<bool> LoginUser(string username, string password)
await _localStorage.SetItemAsync("token", jwtString);
return _authStateProvider.UpdateAuthState(jwtString);
}

public async Task Logout()
{
await _localStorage.RemoveItemAsync("token");
_authStateProvider.UpdateAuthState("");
}
}
}
1 change: 1 addition & 0 deletions Shifty.App/Services/IAuthenticationService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,6 @@ namespace Shifty.App.Services
public interface IAuthenticationService
{
Task<bool> LoginUser(string username, string password);
Task Logout();
}
}
7 changes: 6 additions & 1 deletion Shifty.App/Shared/NavMenu.razor
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
<MudNavMenu>
@using Shifty.App.Services
@inject IAuthenticationService _authenticationService

<MudNavMenu>
<MudNavLink Href="" Match="NavLinkMatch.All" Icon="@Icons.Material.Filled.Home">Home</MudNavLink>
@if (_user is not null && _user.IsInRole("Board"))
{
Expand All @@ -7,6 +10,8 @@
<MudNavLink Href="MenuItems" Match="NavLinkMatch.Prefix" Icon="@Icons.Material.Outlined.Coffee">Menu Item Management</MudNavLink>
<MudNavLink Href="Users" Match="NavLinkMatch.Prefix" Icon="@Icons.Material.Filled.ManageAccounts">Manage users</MudNavLink>
}
<MudDivider />
<MudNavLink OnClick="_authenticationService.Logout" Match="NavLinkMatch.Prefix" Icon="@Icons.Material.Filled.Logout">Logout</MudNavLink>
</MudNavMenu>

@code
Expand Down

0 comments on commit ef22c79

Please sign in to comment.