"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"; import { Eye, EyeOff } from "lucide-react"; export default function SignupPage() { const [name, setName] = useState(""); const [email, setEmail] = useState(""); const [password, setPassword] = useState(""); const [confirmPassword, setConfirmPassword] = useState(""); const [inviteCode, setInviteCode] = useState(""); const [isSubmitting, setIsSubmitting] = useState(false); const [formError, setFormError] = useState(""); const [passwordError, setPasswordError] = useState(""); const [confirmPasswordError, setConfirmPasswordError] = useState(""); const [showPassword, setShowPassword] = useState(false); const [showConfirmPassword, setShowConfirmPassword] = useState(false); const [agreeToTerms, setAgreeToTerms] = 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 ""; }; /** Handle Terms of Service click */ const handleTermsClick = () => { window.open("/Terms", "_blank"); }; /** Handle Privacy Policy click */ const handlePrivacyClick = () => { window.open("/Privacy", "_blank"); }; /** 处理密码输入变化 */ const handlePasswordChange = (e: React.ChangeEvent) => { const newPassword = e.target.value; setPassword(newPassword); if (newPassword) { const error = validatePassword(newPassword); setPasswordError(error); } else { setPasswordError(""); } // 如果确认密码已输入,重新验证确认密码 if (confirmPassword) { if (newPassword !== confirmPassword) { setConfirmPasswordError("Passwords do not match"); } else { setConfirmPasswordError(""); } } }; /** 处理确认密码输入变化 */ const handleConfirmPasswordChange = ( e: React.ChangeEvent ) => { const newConfirmPassword = e.target.value; setConfirmPassword(newConfirmPassword); if (newConfirmPassword) { if (password !== newConfirmPassword) { setConfirmPasswordError("Passwords do not match"); } else { setConfirmPasswordError(""); } } else { setConfirmPasswordError(""); } }; const handleSubmit = async (e: React.FormEvent) => { e.preventDefault(); // 验证密码 const passwordValidationError = validatePassword(password); if (passwordValidationError) { setPasswordError(passwordValidationError); return; } // 验证确认密码 if (password !== confirmPassword) { setConfirmPasswordError("Passwords do not match"); return; } // 验证是否同意条款 if (!agreeToTerms) { setFormError("Please agree to the Terms of Service and Privacy Policy"); 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(error.message || "Registration failed, please try again"); } finally { setIsSubmitting(false); } }; return (
{/* 背景视频 */} {/* 视频遮罩层 */}
{/* Logo */}
router.push("/")} > {/* beta标签 */} Beta
{/* 注册框 - 居中显示 */}

Sign Up, for free

Create your account to get started

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" />
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" />
{passwordError && (

{passwordError}

)} {confirmPasswordError && (

{confirmPasswordError}

)} {password && !passwordError && (

✓ Password format is correct

)} {confirmPassword && !confirmPasswordError && (

✓ Passwords match

)}
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" />
setAgreeToTerms(e.target.checked)} className="mt-1 w-4 h-4 text-purple-600 bg-black/30 border-white/20 rounded focus:ring-purple-500 focus:ring-2" />
{formError && (
{formError}
)}
Back to login
{/*
or
*/}

Already have an account?{" "} Login

); }