feat: JWT 토큰 기반 Admin 로그인 인증 완성

- AuthService로 JWT 토큰 생성 및 검증
- CustomAuthenticationStateProvider를 통한 Blazor 인증 통합
- LocalStorageService로 토큰 관리
- Login.razor 완전 재작성 (실제 DB 검증, 토큰 발급)
- BCrypt 기반 비밀번호 검증
- admin/admin123으로 테스트 가능

Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
This commit is contained in:
2026-06-26 22:00:16 +09:00
parent b2c8b35cdd
commit a039bb53a4
10 changed files with 274 additions and 34 deletions
+38 -14
View File
@@ -1,9 +1,10 @@
@page "/login"
@using System.ComponentModel.DataAnnotations
@using Microsoft.AspNetCore.Authentication
@using Microsoft.AspNetCore.Authentication.Cookies
@layout TaxBaik.Admin.Components.Layout.BlankLayout
@attribute [AllowAnonymous]
@inject AuthService AuthService
@inject NavigationManager NavigationManager
@inject CustomAuthenticationStateProvider AuthStateProvider
<PageTitle>로그인</PageTitle>
@@ -24,7 +25,17 @@
}
<MudButton Variant="Variant.Filled" Color="Color.Primary" FullWidth="true"
Size="Size.Large" OnClick="HandleLogin">로그인</MudButton>
Size="Size.Large" OnClick="HandleLogin" Disabled="isLoading">
@if (isLoading)
{
<MudProgressCircular Size="Size.Small" Indeterminate="true" Class="mr-2" />
<span>로그인 중...</span>
}
else
{
<span>로그인</span>
}
</MudButton>
</MudForm>
</MudPaper>
</MudContainer>
@@ -32,30 +43,43 @@
@code {
private MudForm form;
private bool isFormValid = false;
private bool isLoading = false;
private string errorMessage = "";
private LoginModel model = new();
private async Task HandleLogin()
{
// 기본 사용자명: admin / 비밀번호: admin123
if (model.Username == "admin" && model.Password == "admin123")
if (isLoading)
return;
isLoading = true;
errorMessage = "";
try
{
// 임시: 대시보드로 리다이렉트 (향후 실제 쿠키 인증으로 개선)
NavigationManager.NavigateTo("/taxbaik/admin/dashboard", forceLoad: true);
var token = await AuthService.AuthenticateAndGenerateTokenAsync(model.Username, model.Password);
if (token == null)
{
errorMessage = "사용자명 또는 비밀번호가 올바르지 않습니다.";
isLoading = false;
return;
}
await AuthStateProvider.LoginAsync(token);
NavigationManager.NavigateTo("/taxbaik/admin/dashboard", forceLoad: false);
}
else
catch (Exception ex)
{
errorMessage = "사용자명 또는 비밀번호가 올바르지 않습니다.";
errorMessage = "로그인 중 오류가 발생했습니다.";
isLoading = false;
}
}
[Inject]
private NavigationManager NavigationManager { get; set; }
private class LoginModel
{
public string Username { get; set; }
public string Password { get; set; }
public string Username { get; set; } = "";
public string Password { get; set; } = "";
}
}
+15 -12
View File
@@ -1,14 +1,17 @@
@using Microsoft.AspNetCore.Components.Routing
@using Microsoft.AspNetCore.Components.Authorization
<Router AppAssembly="typeof(Program).Assembly">
<Found Context="routeData">
<RouteView RouteData="routeData" DefaultLayout="typeof(MainLayout)" />
<FocusOnNavigate RouteData="routeData" Selector="h1" />
</Found>
<NotFound>
<PageTitle>찾을 수 없음</PageTitle>
<LayoutView Layout="typeof(MainLayout)">
<p>요청한 페이지를 찾을 수 없습니다.</p>
</LayoutView>
</NotFound>
</Router>
<CascadingAuthenticationState>
<Router AppAssembly="typeof(Program).Assembly">
<Found Context="routeData">
<AuthorizeRouteView RouteData="routeData" DefaultLayout="typeof(MainLayout)" />
<FocusOnNavigate RouteData="routeData" Selector="h1" />
</Found>
<NotFound>
<PageTitle>찾을 수 없음</PageTitle>
<LayoutView Layout="typeof(MainLayout)">
<p>요청한 페이지를 찾을 수 없습니다.</p>
</LayoutView>
</NotFound>
</Router>
</CascadingAuthenticationState>
+2
View File
@@ -7,3 +7,5 @@
@using Microsoft.AspNetCore.Components.Authorization
@using Microsoft.AspNetCore.Authorization
@using MudBlazor
@using TaxBaik.Admin.Services
@attribute [Authorize]