diff --git a/src/pages/LoginPage.tsx b/src/pages/LoginPage.tsx index 20dbbe8..e58d28f 100644 --- a/src/pages/LoginPage.tsx +++ b/src/pages/LoginPage.tsx @@ -6,12 +6,34 @@ import { useAuth } from '../auth/useAuth'; const GOOGLE_CLIENT_ID = '295080817934-1uqaqrkup9jnslajkl1ngpee7gm249fv.apps.googleusercontent.com'; +const redirectPath = new URLSearchParams(window.location.search).get('redirect'); + +async function safeRedirect(path: string) { + try { + const res = await fetch(path, { method: 'HEAD', credentials: 'include' }); + if (res.ok) { + window.location.href = path; + return; + } + } catch { + // 네트워크 오류 + } + window.location.href = '/'; +} + export function LoginPage() { const { user, login, devLogin, loading } = useAuth(); const [error, setError] = useState(null); if (loading) return null; - if (user && user.status === 'ACTIVE') return ; + + if (user && user.status === 'ACTIVE') { + if (redirectPath && redirectPath.startsWith('/')) { + safeRedirect(redirectPath); + return null; + } + return ; + } if (user && user.status === 'PENDING') return ; @@ -19,6 +41,10 @@ export function LoginPage() { setError(null); try { await login(credential); + if (redirectPath && redirectPath.startsWith('/')) { + await safeRedirect(redirectPath); + return; + } } catch (e) { setError( e instanceof Error && e.message @@ -28,6 +54,13 @@ export function LoginPage() { } }; + const handleDevLogin = () => { + devLogin?.(); + if (redirectPath && redirectPath.startsWith('/')) { + safeRedirect(redirectPath); + } + }; + return (
@@ -61,7 +94,7 @@ export function LoginPage() {
{devLogin && (