'use client' import Link from 'next/link' import { useState, Suspense } from 'react' import { useSearchParams, useRouter } from 'next/navigation' import PublicShell from '@/components/PublicShell' import { ADMIN_API_BASE } from '@/lib/api' export default function AdminResetPasswordPage() { return ( ) } function AdminResetPasswordContent() { const searchParams = useSearchParams() const router = useRouter() const token = searchParams.get('token') const [password, setPassword] = useState('') const [showPassword, setShowPassword] = useState(false) const [confirm, setConfirm] = useState('') const [showConfirm, setShowConfirm] = useState(false) const [loading, setLoading] = useState(false) const [done, setDone] = useState(false) const [error, setError] = useState(null) async function handleSubmit(e: React.FormEvent) { e.preventDefault() if (password.length < 8) { setError('Password must be at least 8 characters.'); return } if (password !== confirm) { setError('Passwords do not match.'); return } setLoading(true) setError(null) try { const res = await fetch(`${ADMIN_API_BASE}/admin/auth/reset-password`, { method: 'POST', headers: { 'Content-Type': 'application/json' }, credentials: 'include', body: JSON.stringify({ token, password }), }) const json = await res.json() if (!res.ok) { if (json?.error === 'invalid_token') throw new Error('This reset link is invalid or has expired.') throw new Error('Something went wrong. Please try again.') } setDone(true) } catch (err: any) { setError(err.message ?? 'Something went wrong.') } finally { setLoading(false) } } if (!token) { return ( No reset token found. Request a new reset link ) } if (done) { return ( Password updated You can now sign in with your new password. router.push('/login')} className="mt-2 inline-flex w-full justify-center rounded-full bg-stone-900 px-6 py-3 text-sm font-semibold text-white transition hover:bg-orange-700 dark:bg-orange-400 dark:text-white dark:hover:bg-orange-300" > Sign in ) } return ( {error && ( {error} )} New password setPassword(e.target.value)} placeholder="••••••••" className="w-full rounded-2xl border border-stone-200 bg-white px-4 py-3 pr-10 text-sm text-stone-900 focus:border-transparent focus:outline-none focus:ring-2 focus:ring-orange-500 dark:border-blue-800 dark:bg-[#07101e]/80 dark:text-stone-100" /> setShowPassword((v) => !v)} className="absolute inset-y-0 right-3 flex items-center text-stone-400 hover:text-stone-700 dark:text-stone-500 dark:hover:text-stone-200" tabIndex={-1} > {showPassword ? ( ) : ( )} Confirm password setConfirm(e.target.value)} placeholder="••••••••" className="w-full rounded-2xl border border-stone-200 bg-white px-4 py-3 pr-10 text-sm text-stone-900 focus:border-transparent focus:outline-none focus:ring-2 focus:ring-orange-500 dark:border-blue-800 dark:bg-[#07101e]/80 dark:text-stone-100" /> setShowConfirm((v) => !v)} className="absolute inset-y-0 right-3 flex items-center text-stone-400 hover:text-stone-700 dark:text-stone-500 dark:hover:text-stone-200" tabIndex={-1} > {showConfirm ? ( ) : ( )} {loading ? 'Resetting…' : 'Reset password'} Back to sign in ) } function AdminResetShell({ children }: { children: React.ReactNode }) { return ( RentalDriveGo Reset password {children} ) }
No reset token found.
Password updated
You can now sign in with your new password.