feat: 로그인 redirect 파라미터 처리 #12
@ -6,12 +6,34 @@ import { useAuth } from '../auth/useAuth';
|
|||||||
const GOOGLE_CLIENT_ID =
|
const GOOGLE_CLIENT_ID =
|
||||||
'295080817934-1uqaqrkup9jnslajkl1ngpee7gm249fv.apps.googleusercontent.com';
|
'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() {
|
export function LoginPage() {
|
||||||
const { user, login, devLogin, loading } = useAuth();
|
const { user, login, devLogin, loading } = useAuth();
|
||||||
const [error, setError] = useState<string | null>(null);
|
const [error, setError] = useState<string | null>(null);
|
||||||
|
|
||||||
if (loading) return 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')
|
if (user && user.status === 'PENDING')
|
||||||
return <Navigate to="/pending" replace />;
|
return <Navigate to="/pending" replace />;
|
||||||
|
|
||||||
@ -19,6 +41,10 @@ export function LoginPage() {
|
|||||||
setError(null);
|
setError(null);
|
||||||
try {
|
try {
|
||||||
await login(credential);
|
await login(credential);
|
||||||
|
if (redirectPath && redirectPath.startsWith('/')) {
|
||||||
|
await safeRedirect(redirectPath);
|
||||||
|
return;
|
||||||
|
}
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
setError(
|
setError(
|
||||||
e instanceof Error && e.message
|
e instanceof Error && e.message
|
||||||
@ -28,6 +54,13 @@ export function LoginPage() {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const handleDevLogin = () => {
|
||||||
|
devLogin?.();
|
||||||
|
if (redirectPath && redirectPath.startsWith('/')) {
|
||||||
|
safeRedirect(redirectPath);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<GoogleOAuthProvider clientId={GOOGLE_CLIENT_ID}>
|
<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">
|
<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>
|
</div>
|
||||||
{devLogin && (
|
{devLogin && (
|
||||||
<button
|
<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"
|
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)
|
개발 모드 로그인 (Mock)
|
||||||
|
|||||||
불러오는 중...
Reference in New Issue
Block a user