gc-wing/apps/web/src/shared/auth/ProtectedRoute.tsx
htlee 79b21c7d44 feat(auth): Google OAuth 로그인 구현
- shared/auth 모듈: AuthProvider, ProtectedRoute, useAuth, authApi
- 페이지: LoginPage(Google OAuth), PendingPage, DeniedPage
- WING_PERMIT 역할 기반 접근 제어
- Topbar에 사용자 이름 + 로그아웃 버튼 추가
- App.tsx에 react-router 라우팅 + AuthProvider 래핑
- DEV 모드 Mock 로그인 지원 (김개발)

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-16 08:44:25 +09:00

36 lines
775 B
TypeScript

import { Navigate, Outlet } from 'react-router';
import { useAuth } from './useAuth';
const REQUIRED_ROLE = 'WING_PERMIT';
export function ProtectedRoute() {
const { user, loading } = useAuth();
if (loading) {
return (
<div className="auth-loading">
<div className="auth-loading__spinner" />
</div>
);
}
if (!user) {
return <Navigate to="/login" replace />;
}
if (user.status === 'PENDING') {
return <Navigate to="/pending" replace />;
}
if (user.status === 'REJECTED' || user.status === 'DISABLED') {
return <Navigate to="/denied" replace />;
}
const hasPermit = user.roles.some((r) => r.name === REQUIRED_ROLE);
if (!hasPermit) {
return <Navigate to="/denied" replace />;
}
return <Outlet />;
}