'use client'; import React, { useState, useEffect } from 'react'; const ResetPasswordPage = () => { const [token, setToken] = useState(''); const [newPassword, setNewPassword] = useState(''); const [confirmPassword, setConfirmPassword] = useState(''); const [isLoading, setIsLoading] = useState(false); const [error, setError] = useState(null); const [showSuccess, setShowSuccess] = useState(false); const [hasToken, setHasToken] = useState(false); useEffect(() => { const urlParams = new URLSearchParams(window.location.search); const tokenParam = urlParams.get('token'); if (tokenParam) { setToken(tokenParam); setHasToken(true); } }, []); const handleSubmit = async (e: React.FormEvent) => { e.preventDefault(); setError(null); if (newPassword.length < 6) { setError('Password must be at least 6 characters'); return; } if (newPassword !== confirmPassword) { setError('Passwords do not match'); return; } setIsLoading(true); try { const response = await fetch('/api/auth/reset-password', { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ token, newPassword }), }); const result = await response.json(); if (!response.ok) { throw new Error(result.error || 'Failed to reset password'); } setShowSuccess(true); } catch (err) { setError(err instanceof Error ? err.message : 'An unknown error occurred'); } finally { setIsLoading(false); } }; if (showSuccess) { return (

Password Reset Successful!

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

); } if (!hasToken) { return (

Invalid Reset Link

This reset link is invalid or has expired. Please{' '} request a new one.

); } return (

Weekly To Do List

Choose a new password

{error && (
{error}
)}
setNewPassword(e.target.value)} className="appearance-none rounded-none relative block w-full px-3 py-2 border border-gray-300 placeholder-gray-500 text-gray-900 rounded-t-md focus:outline-none focus:ring-indigo-500 focus:border-indigo-500 focus:z-10 sm:text-sm" placeholder="New Password" />
setConfirmPassword(e.target.value)} className="appearance-none rounded-none relative block w-full px-3 py-2 border border-gray-300 placeholder-gray-500 text-gray-900 rounded-b-md focus:outline-none focus:ring-indigo-500 focus:border-indigo-500 focus:z-10 sm:text-sm" placeholder="Confirm Password" />

Back to login

); }; export default ResetPasswordPage;