"use client"; import { useState } from "react"; import { useRouter } from "next/navigation"; import Link from "next/link"; import { apiRegister } from "@/lib/api"; export default function RegisterPage() { const router = useRouter(); const [username, setUsername] = useState(""); const [email, setEmail] = useState(""); const [password, setPassword] = useState(""); const [error, setError] = useState(""); const [loading, setLoading] = useState(false); const handleSubmit = async (e: React.FormEvent) => { e.preventDefault(); setError(""); setLoading(true); try { const res = await apiRegister(username, email, password); if (res.id) { router.push("/login"); } else { setError(res.error || "注册失败"); } } finally { setLoading(false); } }; return (

注册

{error && (
{error}
)}
setUsername(e.target.value)} required minLength={3} maxLength={32} className="w-full px-3 py-2 rounded-lg border" style={{ borderColor: "var(--border)", background: "var(--bg)", color: "var(--text)" }} />
setEmail(e.target.value)} className="w-full px-3 py-2 rounded-lg border" style={{ borderColor: "var(--border)", background: "var(--bg)", color: "var(--text)" }} />
setPassword(e.target.value)} required minLength={6} className="w-full px-3 py-2 rounded-lg border" style={{ borderColor: "var(--border)", background: "var(--bg)", color: "var(--text)" }} />

已有账号?去登录

); }