From 7b20867f2b16bba921821a30fc9ba25a31baa7db Mon Sep 17 00:00:00 2001 From: htlee Date: Wed, 18 Feb 2026 13:28:35 +0900 Subject: [PATCH] =?UTF-8?q?feat:=20=EB=A1=9C=EA=B7=B8=EC=9D=B8=20redirect?= =?UTF-8?q?=20=ED=8C=8C=EB=9D=BC=EB=AF=B8=ED=84=B0=20=EC=B2=98=EB=A6=AC=20?= =?UTF-8?q?(#11)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/pages/LoginPage.tsx | 37 +++++++++++++++++++++++++++++++++++-- 1 file changed, 35 insertions(+), 2 deletions(-) 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 && (