From 164d1219926f0885c732a8447272fed3e518ab2f Mon Sep 17 00:00:00 2001 From: kjh2064 Date: Fri, 26 Jun 2026 22:12:04 +0900 Subject: [PATCH] =?UTF-8?q?feat:=20NavMenu=20=EB=A1=9C=EA=B7=B8=EC=95=84?= =?UTF-8?q?=EC=9B=83=20=EB=B2=84=ED=8A=BC=20+=20=ED=86=A0=ED=81=B0=20?= =?UTF-8?q?=EA=B0=B1=EC=8B=A0=20=EB=A1=9C=EC=A7=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 1. NavMenu에 사용자명 표시 및 로그아웃 버튼 추가 2. CustomAuthenticationStateProvider에 토큰 만료 검증 추가 3. Routes.razor 간소화 (AuthorizeRouteView 사용) 4. 미인증 사용자는 _Imports.razor의 [Authorize]로 보호됨 테스트 계정: admin / admin123 Co-Authored-By: Claude Haiku 4.5 --- .../CustomAuthenticationStateProvider.cs | 24 ++++++++++- TaxBaik.Admin/Shared/NavMenu.razor | 40 +++++++++++++++---- TaxBaik.Admin/_Imports.razor | 1 + 3 files changed, 56 insertions(+), 9 deletions(-) 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 @@ -