diff --git a/app/login/page.tsx b/app/login/page.tsx index ab62211..353aad0 100644 --- a/app/login/page.tsx +++ b/app/login/page.tsx @@ -1,12 +1,13 @@ 'use client'; import { useState, useEffect } from 'react'; -import { useRouter } from 'next/navigation'; +import { useRouter, useSearchParams } from 'next/navigation'; import Link from 'next/link'; import { useAuth } from '@/lib/auth'; export default function LoginPage() { const router = useRouter(); + const searchParams = useSearchParams(); const { signIn, signInWithGitHub, signInWithGoogle, user } = useAuth(); const [email, setEmail] = useState(''); @@ -14,6 +15,14 @@ export default function LoginPage() { const [isLoading, setIsLoading] = useState(false); const [message, setMessage] = useState({ type: '', content: '' }); + // 读取URL中的消息参数 + useEffect(() => { + const messageParam = searchParams.get('message'); + if (messageParam) { + setMessage({ type: 'info', content: messageParam }); + } + }, [searchParams]); + // 如果用户已登录,重定向到首页 useEffect(() => { if (user) { @@ -112,11 +121,16 @@ export default function LoginPage() { {/* Message display */} {message.content && ( -
+ {message.type === 'error' ? ( + Error: + ) : ( + Notice: + )} {message.content}
)} diff --git a/lib/auth.tsx b/lib/auth.tsx index ab8b200..30f460c 100644 --- a/lib/auth.tsx +++ b/lib/auth.tsx @@ -160,6 +160,9 @@ export const AuthProvider: React.FC<{ children: React.ReactNode }> = ({ children const { error } = await supabase.auth.signUp({ email, password, + options: { + emailRedirectTo: `${window.location.origin}/auth/callback`, + } }); if (error) { @@ -168,7 +171,7 @@ export const AuthProvider: React.FC<{ children: React.ReactNode }> = ({ children } // 注册成功后跳转到登录页面并显示确认消息 - router.push('/login?message=注册成功,请查看邮箱确认账户'); + router.push('/login?message=Registration successful! Please check your email to verify your account before logging in.'); } catch (error) { console.error('注册过程出错:', error); throw error;