'use client'; import { useState, FormEvent } from 'react'; import Link from 'next/link'; import { useAuth } from '@/lib/auth'; export default function RegisterPage() { const [email, setEmail] = useState(''); const [password, setPassword] = useState(''); const [confirmPassword, setConfirmPassword] = useState(''); const [error, setError] = useState(null); const [isLoading, setIsLoading] = useState(false); const { signUp, signInWithGoogle } = useAuth(); // 处理注册表单提交 const handleSubmit = async (e: FormEvent) => { e.preventDefault(); setError(null); // 验证密码 if (password !== confirmPassword) { setError('两次输入的密码不一致'); return; } // 密码强度验证 if (password.length < 6) { setError('密码长度至少为6个字符'); return; } setIsLoading(true); try { await signUp(email, password); // 注册成功后会跳转到登录页面,提示用户验证邮箱 } catch (error) { console.error('Registration error:', error); setError('注册失败,请稍后再试或使用其他邮箱'); } finally { setIsLoading(false); } }; // 处理Google注册/登录 const handleGoogleSignIn = async () => { setError(null); try { await signInWithGoogle(); // 登录流程会重定向到Google,然后回到应用 } catch (error) { console.error('Google sign in error:', error); setError('Google登录失败,请稍后再试'); } }; return (

注册

创建您的帐户以访问分析仪表板

{/* 错误提示 */} {error && (
{error}
)}
setEmail(e.target.value)} className="mt-1 block w-full px-3 py-2 border border-gray-300 dark:border-gray-600 rounded-md shadow-sm placeholder-gray-400 dark:placeholder-gray-500 dark:bg-gray-700 dark:text-white focus:outline-none focus:ring-blue-500 focus:border-blue-500" placeholder="your@email.com" />
setPassword(e.target.value)} className="mt-1 block w-full px-3 py-2 border border-gray-300 dark:border-gray-600 rounded-md shadow-sm placeholder-gray-400 dark:placeholder-gray-500 dark:bg-gray-700 dark:text-white focus:outline-none focus:ring-blue-500 focus:border-blue-500" placeholder="********" />
setConfirmPassword(e.target.value)} className="mt-1 block w-full px-3 py-2 border border-gray-300 dark:border-gray-600 rounded-md shadow-sm placeholder-gray-400 dark:placeholder-gray-500 dark:bg-gray-700 dark:text-white focus:outline-none focus:ring-blue-500 focus:border-blue-500" placeholder="********" />

已有账号?{' '} 登录

); }