'use client' import { useState } from 'react' import { useRouter, useParams } from 'next/navigation' import Link from 'next/link' import { toast } from 'sonner' import { Button } from '@/components/ui/button' import { Input } from '@/components/ui/input' import { Card, CardHeader, CardTitle, CardDescription, CardContent } from '@/components/ui/card' import { authAPI } from '@/lib/api' export default function ResetPasswordPage() { const router = useRouter() const params = useParams() const token = params.token as string const [password, setPassword] = useState('') const [confirmPassword, setConfirmPassword] = useState('') const [isLoading, setIsLoading] = useState(false) const [success, setSuccess] = useState(false) const handleSubmit = async (e: React.FormEvent) => { e.preventDefault() // Client-side validation if (password !== confirmPassword) { toast.error('Passwords do not match') return } if (password.length < 8) { toast.error('Password must be at least 8 characters') return } if (!/[A-Z]/.test(password)) { toast.error('Password must contain at least one uppercase letter') return } if (!/[a-z]/.test(password)) { toast.error('Password must contain at least one lowercase letter') return } if (!/[0-9]/.test(password)) { toast.error('Password must contain at least one number') return } setIsLoading(true) try { await authAPI.resetPassword(token, password) setSuccess(true) toast.success('Password reset successfully!') // Redirect to login after 2 seconds setTimeout(() => { router.push('/login') }, 2000) } catch (error: any) { console.error('Reset password error:', error) const message = error.response?.data?.message || 'Failed to reset password. The link may have expired.' toast.error(message) } finally { setIsLoading(false) } } return (
{/* Logo */}
Website Monitor
Set New Password {success ? 'Your password has been reset' : 'Choose a strong password for your account'} {!success ? (
setPassword(e.target.value)} placeholder="••••••••" required disabled={isLoading} hint="At least 8 characters, including uppercase, lowercase, and number" /> setConfirmPassword(e.target.value)} placeholder="••••••••" required disabled={isLoading} /> {/* Password Requirements */}

Password must contain:

  • = 8 ? 'text-green-600' : 'text-muted-foreground'}> {password.length >= 8 ? '✓' : '○'} At least 8 characters
  • {/[A-Z]/.test(password) ? '✓' : '○'} One uppercase letter
  • {/[a-z]/.test(password) ? '✓' : '○'} One lowercase letter
  • {/[0-9]/.test(password) ? '✓' : '○'} One number
  • 0 ? 'text-green-600' : 'text-muted-foreground'}> {password === confirmPassword && password.length > 0 ? '✓' : '○'} Passwords match
Back to Login
) : (

Password Reset Successfully!

You can now log in with your new password.

Redirecting to login page...

)}
) }