"use client"; import React, { useState } from "react"; import { useRouter } from "next/navigation"; import Link from "next/link"; import { signInWithGoogle, registerUser } from "@/lib/auth"; import { GradientText } from "@/components/ui/gradient-text"; export default function SignupPage() { const [name, setName] = useState(""); const [email, setEmail] = useState(""); const [password, setPassword] = useState(""); const [inviteCode, setInviteCode] = useState(""); const [isSubmitting, setIsSubmitting] = useState(false); const [formError, setFormError] = useState(""); const [passwordError, setPasswordError] = useState(""); const [showPassword, setShowPassword] = useState(false); const router = useRouter(); /** Password validation function with English prompts */ const validatePassword = (password: string): string => { if (password.length < 8) { return "Password must be at least 8 characters"; } if (password.length > 18) { return "Password cannot exceed 18 characters"; } if (!/^(?=.*[a-zA-Z])(?=.*\d)[a-zA-Z\d]{8,18}$/.test(password)) { return "Password must contain both letters and numbers"; } return ""; }; /** 处理密码输入变化 */ const handlePasswordChange = (e: React.ChangeEvent) => { const newPassword = e.target.value; setPassword(newPassword); if (newPassword) { const error = validatePassword(newPassword); setPasswordError(error); } else { setPasswordError(""); } }; const handleSubmit = async (e: React.FormEvent) => { e.preventDefault(); // 验证密码 const passwordValidationError = validatePassword(password); if (passwordValidationError) { setPasswordError(passwordValidationError); return; } setIsSubmitting(true); setFormError(""); try { // Use new registration API await registerUser({ userName: name, email, password, inviteCode: inviteCode || undefined, }); // Redirect to login page after successful registration router.push("/login?registered=true"); } catch (error: any) { console.error("Signup error:", error); setFormError("Registration failed, please try again"); } finally { setIsSubmitting(false); } }; const handleGoogleSignIn = () => { signInWithGoogle(); }; return (
{/* 背景视频 */} {/* 视频遮罩层 */}
{/* Logo */}
router.push("/")} > {/* beta标签 */} Beta
{/* 注册框 - 居中显示 */}

Sign Up, for free

Create your account to get started

setName(e.target.value)} required className="w-full px-4 py-3 rounded-lg bg-black/30 border border-white/20 text-white placeholder-gray-400 focus:outline-none focus:ring-2 focus:ring-purple-500 focus:border-transparent" />
setEmail(e.target.value)} required className="w-full px-4 py-3 rounded-lg bg-black/30 border border-white/20 text-white placeholder-gray-400 focus:outline-none focus:ring-2 focus:ring-purple-500 focus:border-transparent" />
{passwordError && (

{passwordError}

)} {password && !passwordError && (

✓ Password format is correct

)}

Password requirements: 8-18 characters, must contain letters and numbers

setInviteCode(e.target.value)} className="w-full px-4 py-3 rounded-lg bg-black/30 border border-white/20 text-white placeholder-gray-400 focus:outline-none focus:ring-2 focus:ring-purple-500 focus:border-transparent" />
{formError && (
{formError}
)}
Back to login
{/*
or
*/}

Already have an account?{" "} Login

); }