feat(frontend): 인증 연동 (로그인/로그아웃/내정보/라우트 가드)

- 로그인 실연동: 성공 시 access/refresh 토큰 저장, me 캐시 무효화
- SidebarFooter: useMeQuery 로 공급사명 표시, useLogoutMutation 로 로그아웃
- RequireAuth 가드로 /list·/chat 보호, 토큰 없으면 로그인으로
- 인증 만료/폐기 시 로그인 페이지로 이동(setUnauthorizedHandler)
- LoginPage: 이미 로그인 상태면 목록으로 리다이렉트

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
민헌andClaude Opus 4.8 committed 2026-06-18 13:12:23 +09:00
1 parent 7bdd10207a
commit c0d224ef21
6 files changed
+60 -18

No files matched your search

@@ -0,0 +1,12 @@
import type { ReactNode } from 'react'
import { Navigate } from 'react-router'
import { tokenStorage } from '@/apis'
// 토큰이 없으면 로그인 페이지로 보낸다 (인증 영역 가드).
// 토큰이 있으나 만료/폐기된 경우는 요청 시 인터셉터가 세션을 종료시킨다.
export function RequireAuth({ children }: { children: ReactNode }) {
if (!tokenStorage.hasToken()) {
return <Navigate to="/" replace />
}
return <>{children}</>
}
@@ -1,18 +1,30 @@
import { useNavigate } from 'react-router'
import { useLogoutMutation, useMeQuery } from '@/apis'
import { Button } from '@/components'
// 사이드바 하단: 공급사명 + 로그아웃
export function SidebarFooter() {
const navigate = useNavigate()
const { data: user } = useMeQuery()
const logout = useLogoutMutation()
const handleLogout = () => {
logout.mutate(undefined, {
onSuccess: () => navigate('/'),
})
}
return (
<div className="flex w-full h-[60px] py-3 px-8 gap-3 items-center">
<div className="flex-1 flex items-center min-w-0 text-sm text-foreground">
{/* TODO: 공급사명 (auth store 연동) */}
<span className="truncate">-</span>
<span className="truncate">{user?.supplierName ?? '-'}</span>
</div>
<Button
variant="secondary"
size="sm"
className="w-[61px] px-2 rounded-[4px] text-xs flex-shrink-0"
// TODO: 로그아웃 mutation 연동
onClick={handleLogout}
disabled={logout.isPending}
>
로그아웃
</Button>
@@ -1,13 +1,2 @@
import { useMutation } from '@tanstack/react-query'
export interface LoginParams {
id: string
password: string
}
// 임시 stub (검증만 통과하면 성공). TODO: 로그인 API 연동
export function useLoginMutation() {
return useMutation<void, Error, LoginParams>({
mutationFn: async () => {},
})
}
// 실제 로그인 API 연동은 apis/auth 로 이전됨. 기존 import 경로 호환을 위해 재노출한다.
export { useLoginMutation, type LoginParams } from '@/apis/auth'
+1
View File
@@ -1,2 +1,3 @@
export { LoginForm } from '@/features/auth/components/LoginForm'
export { SidebarFooter } from '@/features/auth/components/SidebarFooter'
export { RequireAuth } from '@/features/auth/components/RequireAuth'