Merge pull request 'feat: 로그인 redirect 파라미터 처리' (#12) from develop into main
All checks were successful
Build and Deploy / build-and-deploy (push) Successful in 16s

Reviewed-on: #12
This commit is contained in:
htlee 2026-02-18 13:30:53 +09:00
커밋 2282f0b772

파일 보기

@ -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<string | null>(null);
if (loading) return null;
if (user && user.status === 'ACTIVE') return <Navigate to="/" replace />;
if (user && user.status === 'ACTIVE') {
if (redirectPath && redirectPath.startsWith('/')) {
safeRedirect(redirectPath);
return null;
}
return <Navigate to="/" replace />;
}
if (user && user.status === 'PENDING')
return <Navigate to="/pending" replace />;
@ -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 (
<GoogleOAuthProvider clientId={GOOGLE_CLIENT_ID}>
<div className="min-h-screen bg-gradient-to-br from-slate-900 via-blue-950 to-slate-900 flex items-center justify-center px-4">
@ -61,7 +94,7 @@ export function LoginPage() {
</div>
{devLogin && (
<button
onClick={devLogin}
onClick={handleDevLogin}
className="mt-4 w-full px-4 py-2 bg-amber-500/10 text-amber-600 border border-amber-500/30 rounded-lg text-sm font-medium hover:bg-amber-500/20 cursor-pointer"
>
(Mock)