Skip to content

Commit 967b69a

Browse files
ImTotemclaude
andcommitted
feat: 회원가입 1단계에서 이미 가입된 계정 자동 감지
Google OAuth 직후 로그인 API를 먼저 호출하여 가입 여부 확인. 이미 가입된 계정이면 바로 로그인 처리 + 안내 toast. 미가입 계정이면 위저드 계속 진행. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 3ca6c39 commit 967b69a

1 file changed

Lines changed: 39 additions & 10 deletions

File tree

src/pages/register/steps/GoogleStep.tsx

Lines changed: 39 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,59 @@
11
import { GoogleLogin } from "@react-oauth/google";
22
import { Alert, AlertDescription } from "@/components/ui/alert";
3+
import { Loader2 } from "lucide-react";
34
import { useState } from "react";
5+
import { useNavigate } from "react-router-dom";
6+
import { postLogin } from "@/api/auth";
7+
import { toast } from "sonner";
48

59
interface GoogleStepProps {
610
onComplete: (googleToken: string) => void;
711
}
812

913
export function GoogleStep({ onComplete }: GoogleStepProps) {
1014
const [error, setError] = useState(false);
15+
const [checking, setChecking] = useState(false);
16+
const navigate = useNavigate();
17+
18+
const handleSuccess = async (credential: string) => {
19+
setChecking(true);
20+
setError(false);
21+
try {
22+
await postLogin({ google_token: credential });
23+
// 로그인 성공 = 이미 가입된 계정
24+
toast.info("이미 가입된 계정입니다. 로그인되었습니다.");
25+
navigate("/members");
26+
} catch {
27+
// 로그인 실패 = 미가입 계정 → 회원가입 진행
28+
onComplete(credential);
29+
} finally {
30+
setChecking(false);
31+
}
32+
};
1133

1234
return (
1335
<div className="space-y-4">
1436
<p className="text-center text-sm text-muted-foreground">
1537
Google 계정으로 인증해주세요.
1638
</p>
1739
<div className="flex justify-center">
18-
<GoogleLogin
19-
onSuccess={(response) => {
20-
if (response.credential) {
21-
onComplete(response.credential);
22-
}
23-
}}
24-
onError={() => setError(true)}
25-
size="large"
26-
width="300"
27-
/>
40+
{checking ? (
41+
<div className="flex items-center gap-2 py-2 text-sm text-muted-foreground">
42+
<Loader2 className="h-4 w-4 animate-spin" />
43+
확인 중...
44+
</div>
45+
) : (
46+
<GoogleLogin
47+
onSuccess={(response) => {
48+
if (response.credential) {
49+
handleSuccess(response.credential);
50+
}
51+
}}
52+
onError={() => setError(true)}
53+
size="large"
54+
width="300"
55+
/>
56+
)}
2857
</div>
2958
{error && (
3059
<Alert variant="destructive">

0 commit comments

Comments
 (0)