diff --git a/TaxBaik.Admin/Services/CustomAuthenticationStateProvider.cs b/TaxBaik.Admin/Services/CustomAuthenticationStateProvider.cs index 602a5c5..a059b9b 100644 --- a/TaxBaik.Admin/Services/CustomAuthenticationStateProvider.cs +++ b/TaxBaik.Admin/Services/CustomAuthenticationStateProvider.cs @@ -1,3 +1,4 @@ +using System.IdentityModel.Tokens.Jwt; using System.Security.Claims; using Microsoft.AspNetCore.Components.Authorization; @@ -27,6 +28,13 @@ public class CustomAuthenticationStateProvider : AuthenticationStateProvider return new AuthenticationState(new ClaimsPrincipal(new ClaimsIdentity())); } + if (IsTokenExpired(token)) + { + _logger.LogWarning("토큰 만료됨"); + await _localStorage.RemoveItemAsync("auth_token"); + return new AuthenticationState(new ClaimsPrincipal(new ClaimsIdentity())); + } + var principal = _authService.ValidateToken(token); if (principal == null) { @@ -46,8 +54,6 @@ public class CustomAuthenticationStateProvider : AuthenticationStateProvider public async Task LoginAsync(string token) { await _localStorage.SetItemAsStringAsync("auth_token", token); - - var principal = _authService.ValidateToken(token); NotifyAuthenticationStateChanged(GetAuthenticationStateAsync()); } @@ -56,4 +62,18 @@ public class CustomAuthenticationStateProvider : AuthenticationStateProvider await _localStorage.RemoveItemAsync("auth_token"); NotifyAuthenticationStateChanged(GetAuthenticationStateAsync()); } + + private bool IsTokenExpired(string token) + { + try + { + var handler = new JwtSecurityTokenHandler(); + var jwtToken = handler.ReadJwtToken(token); + return jwtToken.ValidTo < DateTime.UtcNow; + } + catch + { + return true; + } + } } diff --git a/TaxBaik.Admin/Shared/NavMenu.razor b/TaxBaik.Admin/Shared/NavMenu.razor index 219e124..ddb2446 100644 --- a/TaxBaik.Admin/Shared/NavMenu.razor +++ b/TaxBaik.Admin/Shared/NavMenu.razor @@ -1,6 +1,26 @@ -