"use client" import { Suspense, useState } from "react" import { useSearchParams } from "next/navigation" import { Card, CardContent, CardHeader, CardTitle, CardDescription } from "@/components/ui/card" import { Button } from "@/components/ui/button" import { Input } from "@/components/ui/input" import { Label } from "@/components/ui/label" import { Lock, CheckCircle, XCircle, Loader2 } from "lucide-react" import Link from "next/link" import { getApiUrl } from "@/lib/api-config" function ResetPasswordContent() { 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 [error, setError] = useState("") const handleSubmit = async (e: React.FormEvent) => { e.preventDefault() setError("") if (password !== confirmPassword) { setError("Passwords don't match") return } if (password.length < 8) { setError("Password must be at least 8 characters") return } setLoading(true) try { const res = await fetch(`${getApiUrl()}/auth/reset-password`, { method: "POST", headers: { "Content-Type": "application/json" }, body: JSON.stringify({ token, new_password: password }) }) if (res.ok) { setSuccess(true) } else { const data = await res.json() setError(data.detail || "Failed to reset password") } } catch (_) { setError("An error occurred. Please try again.") } finally { setLoading(false) } } if (!token) { return (
Loading...