"use client"; import { useState, Suspense, useEffect } from "react"; import { useSearchParams } from "next/navigation"; import { Card, CardContent } from "~/components/ui/card"; import { Input } from "~/components/ui/input"; import { Button } from "~/components/ui/button"; import { Label } from "~/components/ui/label"; import { toast } from "sonner"; import { Logo } from "~/components/branding/logo"; import { LegalModal } from "~/components/ui/legal-modal"; import { Lock, ArrowRight, ArrowLeft, CheckCircle, Shield, Eye, EyeOff, } from "lucide-react"; function ResetPasswordForm() { const searchParams = useSearchParams(); const token = searchParams.get("token"); const [password, setPassword] = useState(""); const [confirmPassword, setConfirmPassword] = useState(""); const [loading, setLoading] = useState(false); const [success, setSuccess] = useState(false); const [showPassword, setShowPassword] = useState(false); const [showConfirmPassword, setShowConfirmPassword] = useState(false); const [tokenValid, setTokenValid] = useState(null); useEffect(() => { if (!token) { setTokenValid(false); return; } // Validate token on page load const validateToken = async () => { try { const response = await fetch("/api/auth/validate-reset-token", { method: "POST", headers: { "Content-Type": "application/json", }, body: JSON.stringify({ token }), }); if (response.ok) { setTokenValid(true); } else { setTokenValid(false); } } catch { setTokenValid(false); } }; void validateToken(); }, [token]); async function handleSubmit(e: React.FormEvent) { e.preventDefault(); if (!token) { toast.error("Invalid reset token"); return; } if (password.length < 8) { toast.error("Password must be at least 8 characters long"); return; } if (password !== confirmPassword) { toast.error("Passwords do not match"); return; } setLoading(true); try { const response = await fetch("/api/auth/reset-password", { method: "POST", headers: { "Content-Type": "application/json", }, body: JSON.stringify({ token, password }), }); const data = (await response.json()) as { error?: string }; if (response.ok) { setSuccess(true); toast.success("Password reset successfully!"); } else { toast.error(data.error ?? "Failed to reset password"); } } catch { toast.error("An error occurred. Please try again."); } finally { setLoading(false); } } if (tokenValid === null) { return (

Validating reset token...

); } if (tokenValid === false) { return (
{/* Hero Section - Hidden on mobile */}

Invalid or expired link

This password reset link is either invalid or has expired. Please request a new password reset.

Security First

Reset links expire after 24 hours for your security

{/* Error Form */}
{/* Mobile Logo */}

Link Expired

This password reset link is no longer valid

); } if (success) { return (
{/* Hero Section - Hidden on mobile */}

Password reset complete

Your password has been successfully reset. You can now sign in with your new password.

Security Updated

Your account is now secured with your new password

{/* Success Form */}
{/* Mobile Logo */}

Password Reset Complete

Your password has been successfully updated

); } return (
{/* Hero Section - Hidden on mobile */}

Create your new password

Choose a strong password to secure your beenvoice account. Make sure it's something you'll remember.

Secure Password

Use at least 8 characters with a mix of letters and numbers

Account Safety

Your new password will immediately secure your account

{/* Reset Password Form */}
{/* Mobile Logo */}

Reset Password

Enter your new password below

setPassword(e.target.value)} required autoFocus className="h-11 pr-10 pl-10" placeholder="Enter new password" minLength={8} />

Must be at least 8 characters long

setConfirmPassword(e.target.value)} required className="h-11 pr-10 pl-10" placeholder="Confirm new password" />
By resetting your password, you agree to our{" "} Terms of Service } />{" "} and{" "} Privacy Policy } /> .
); } export default function ResetPasswordPage() { return ( Loading...}> ); }