"use client" import { useState } from "react" import { useRouter } from "next/navigation" import Link from "next/link" import { Button } from "@/components/ui/button" import { Input } from "@/components/ui/input" import { Label } from "@/components/ui/label" import { Card, CardContent, CardDescription, CardFooter, CardHeader, CardTitle } from "@/components/ui/card" import { Alert, AlertDescription } from "@/components/ui/alert" import { BookOpen } from "lucide-react" export default function RegisterPage() { const router = useRouter() const [name, setName] = useState("") const [email, setEmail] = useState("") const [password, setPassword] = useState("") const [confirmPassword, setConfirmPassword] = useState("") const [error, setError] = useState("") const [loading, setLoading] = useState(false) const handleSubmit = async (e: React.FormEvent) => { e.preventDefault() setError("") if (password !== confirmPassword) { setError("两次输入的密码不一致") return } if (password.length < 6) { setError("密码至少需要6个字符") return } setLoading(true) try { const response = await fetch("/api/auth/register", { method: "POST", headers: { "Content-Type": "application/json", }, body: JSON.stringify({ name, email, password, }), }) const data = await response.json() if (!response.ok) { setError(data.error || "注册失败") return } // 注册成功,跳转到登录页 router.push("/auth/signin?registered=true") } catch (err) { setError("注册失败,请稍后重试") } finally { setLoading(false) } } return (
注册 创建您的华夏谱账号
{error && ( {error} )} 💡 系统已有测试账号,建议直接登录使用
setName(e.target.value)} disabled={loading} />
setEmail(e.target.value)} required disabled={loading} />
setPassword(e.target.value)} required disabled={loading} />
setConfirmPassword(e.target.value)} required disabled={loading} />
已有账号?{" "} 立即登录
) }