feat(auth) : improve Google account handling

This commit is contained in:
2026-10-12 00:51:29 +07:00 Unverified
parent e2af59292c
commit fdbabecf56
7 changed files with 80 additions and 11 deletions
+11
View File
@@ -37,6 +37,8 @@ export function AccountForm({
googleEnabled,
verified,
verificationError,
accountNotLinkedError,
googleSignInError,
}: {
mode: "login" | "register";
siteKey: string;
@@ -44,6 +46,8 @@ export function AccountForm({
googleEnabled: boolean;
verified?: boolean;
verificationError?: boolean;
accountNotLinkedError?: boolean;
googleSignInError?: boolean;
}) {
const router = useRouter();
const register = mode === "register";
@@ -120,6 +124,7 @@ export function AccountForm({
const result = await authClient.signIn.social({
provider: "google",
callbackURL: nextPath,
errorCallbackURL: `/auth/login?googleError=1${nextPath === "/" ? "" : `&next=${encodeURIComponent(nextPath)}`}`,
newUserCallbackURL: `/auth/register?step=profile&next=${encodeURIComponent(nextPath)}`,
fetchOptions: { headers: captcha ? { "x-captcha-response": token } : undefined },
});
@@ -228,6 +233,12 @@ export function AccountForm({
<CardContent className="flex flex-col gap-4">
{verified && <Alert><AlertDescription>ยืนยันอีเมลแล้ว กรุณาเข้าสู่ระบบ</AlertDescription></Alert>}
{verificationError && <Alert variant="destructive"><AlertDescription>ลิงก์ยืนยันไม่ถูกต้องหรือหมดอายุ กรุณาขอลิงก์ใหม่</AlertDescription></Alert>}
{googleSignInError && <Alert variant="destructive" role="alert"><AlertDescription>
เข้าสู่ระบบด้วย Google ไม่สำเร็จ กรุณาลองอีกครั้ง
</AlertDescription></Alert>}
{accountNotLinkedError && <Alert variant="destructive" role="alert"><AlertDescription>
บัญชี Google นี้ยังไม่ได้เชื่อมกับบัญชี Buzz Guide ของคุณ กรุณาเข้าสู่ระบบด้วยอีเมลและรหัสผ่าน แล้วเชื่อม Google ในหน้าโปรไฟล์
</AlertDescription></Alert>}
{notice && <Alert role="status"><AlertDescription>{notice}</AlertDescription></Alert>}
<form ref={formRef} onSubmit={submit}>
<FieldGroup>