From f779a277a8365e025bbc18602db320fc576d33ab Mon Sep 17 00:00:00 2001 From: songtianlun Date: Sat, 14 Jun 2025 21:34:28 +0800 Subject: [PATCH] fix captcha show --- app/auth/signin/page.tsx | 25 +++++- components/captcha-dialog.tsx | 165 +++++++++++++++++++--------------- 2 files changed, 113 insertions(+), 77 deletions(-) diff --git a/app/auth/signin/page.tsx b/app/auth/signin/page.tsx index 7f62a68..34b61d0 100644 --- a/app/auth/signin/page.tsx +++ b/app/auth/signin/page.tsx @@ -58,7 +58,12 @@ function SignInContent() { const handleEmailSignInClick = (e: React.FormEvent) => { e.preventDefault() - if (!email) return + if (!email.trim()) return + + // 清除之前的消息 + setMessage("") + + // 显示验证码弹窗 setShowCaptcha(true) } @@ -68,7 +73,7 @@ function SignInContent() { try { const result = await signIn("nodemailer", { - email, + email: email.trim(), redirect: false, }) @@ -78,6 +83,7 @@ function SignInContent() { setMessage("登录链接已发送到您的邮箱,请查收") } } catch (error) { + console.error("Email sign in error:", error) setMessage("登录失败,请重试") } finally { setIsLoading(false) @@ -86,14 +92,24 @@ function SignInContent() { const handleCaptchaCancel = () => { setMessage("") + setIsLoading(false) + } + + const handleCaptchaOpenChange = (open: boolean) => { + setShowCaptcha(open) + if (!open) { + setIsLoading(false) + } } const handleGoogleSignIn = async () => { setIsLoading(true) + setMessage("") try { const callbackUrl = searchParams.get("callbackUrl") || "/" await signIn("google", { callbackUrl }) } catch (error) { + console.error("Google sign in error:", error) setMessage("Google登录失败,请重试") setIsLoading(false) } @@ -145,12 +161,13 @@ function SignInContent() { onChange={(e) => setEmail(e.target.value)} required className="bg-background border-input" + disabled={isLoading} /> +
+
+
+
+ {num1} + {num2} = ? +
+
+ +
-
-
- - setUserAnswer(e.target.value)} - onKeyPress={handleKeyPress} - className="text-center text-lg font-medium" - autoFocus - /> -
+
+ + setUserAnswer(e.target.value)} + onKeyDown={handleKeyPress} + className="text-center text-lg font-medium" + autoFocus + /> +
- {error && ( - - - {error} - - )} + {error && ( + + + {error} + + )} + - - - - - - + + + + + + ) } \ No newline at end of file