Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 15 additions & 2 deletions src/components/RouteGuards.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import type { UserRole } from '../types/index';
import { useEffect, useState } from 'react';
import { Navigate, useLocation } from 'react-router-dom';
import { useAuthStore } from '../store/useAuthStore';
import { goLogin } from '../auth/hostedUi';

// 곡톡 Props νƒ€μž…
interface RouteGuardProps {
Expand Down Expand Up @@ -33,7 +34,13 @@ export const ProtectedRoute = ({ children }: RouteGuardProps) => {
// λ‘œκ·ΈμΈν•˜μ§€ μ•Šμ•˜λ‹€λ©΄ 둜그인 νŽ˜μ΄μ§€λ‘œ λ¦¬λ‹€μ΄λ ‰νŠΈ
// state에 ν˜„μž¬ μœ„μΉ˜λ₯Ό μ €μž₯ν•΄μ„œ 둜그인 ν›„ λ‹€μ‹œ λŒμ•„μ˜¬ 수 있게 함
if (!isAuthenticated) {
return <Navigate to="/login" state={{ from: location }} replace />;
// ν™ˆ 경둜일 λ•ŒλŠ” κ°€λ“œ μž‘λ™ν•˜μ§€ μ•ŠμŒ
if (location.pathname === '/') {
return <>{children}</>;
}
// λ‹€λ₯Έ 보호된 νŽ˜μ΄μ§€μΌ λ•Œλ§Œ Cognito 둜그인 UI둜 λ¦¬λ‹€μ΄λ ‰νŠΈ
goLogin();
return null;
}

// λ‘œκ·ΈμΈν–ˆλ‹€λ©΄ μ›λž˜ 보렀던 νŽ˜μ΄μ§€ ν‘œμ‹œ
Expand All @@ -56,7 +63,13 @@ export const RoleGuard = ({ children, requiredRole, fallbackPath = '/' }: RoleGu

// λ‘œκ·ΈμΈν•˜μ§€ μ•Šμ•˜λ‹€λ©΄ 둜그인 νŽ˜μ΄μ§€λ‘œ
if (!isAuthenticated) {
return <Navigate to="/login" state={{ from: location }} replace />;
// ν™ˆ 경둜일 λ•ŒλŠ” κ°€λ“œ μž‘λ™ν•˜μ§€ μ•ŠμŒ
if (location.pathname === '/') {
return <>{children}</>;
}
// λ‹€λ₯Έ 보호된 νŽ˜μ΄μ§€μΌ λ•Œλ§Œ Cognito 둜그인 UI둜 λ¦¬λ‹€μ΄λ ‰νŠΈ
goLogin();
return null;
}

// λ‘œκ·ΈμΈν–ˆμ§€λ§Œ κΆŒν•œμ΄ μ—†λ‹€λ©΄ fallback 경둜둜
Expand Down