From ef22c7948b0ccf775b7742af69326a34d676df85 Mon Sep 17 00:00:00 2001 From: Andreas Guldborg Hansen Date: Wed, 6 Mar 2024 08:44:58 +0100 Subject: [PATCH] Adds logout button (#30) * Logout button * Simplify code --- Shifty.App/Services/AuthenticationService.cs | 6 ++++++ Shifty.App/Services/IAuthenticationService.cs | 1 + Shifty.App/Shared/NavMenu.razor | 7 ++++++- 3 files changed, 13 insertions(+), 1 deletion(-) diff --git a/Shifty.App/Services/AuthenticationService.cs b/Shifty.App/Services/AuthenticationService.cs index fa4f1aa..7987a3c 100644 --- a/Shifty.App/Services/AuthenticationService.cs +++ b/Shifty.App/Services/AuthenticationService.cs @@ -47,5 +47,11 @@ public async Task LoginUser(string username, string password) await _localStorage.SetItemAsync("token", jwtString); return _authStateProvider.UpdateAuthState(jwtString); } + + public async Task Logout() + { + await _localStorage.RemoveItemAsync("token"); + _authStateProvider.UpdateAuthState(""); + } } } \ No newline at end of file diff --git a/Shifty.App/Services/IAuthenticationService.cs b/Shifty.App/Services/IAuthenticationService.cs index aab946f..00c16e7 100644 --- a/Shifty.App/Services/IAuthenticationService.cs +++ b/Shifty.App/Services/IAuthenticationService.cs @@ -5,5 +5,6 @@ namespace Shifty.App.Services public interface IAuthenticationService { Task LoginUser(string username, string password); + Task Logout(); } } \ No newline at end of file diff --git a/Shifty.App/Shared/NavMenu.razor b/Shifty.App/Shared/NavMenu.razor index cd8fb9a..5fe57e7 100644 --- a/Shifty.App/Shared/NavMenu.razor +++ b/Shifty.App/Shared/NavMenu.razor @@ -1,4 +1,7 @@ - +@using Shifty.App.Services +@inject IAuthenticationService _authenticationService + + Home @if (_user is not null && _user.IsInRole("Board")) { @@ -7,6 +10,8 @@ Menu Item Management Manage users } + + Logout @code