import { useState } from 'react'; import { Button } from '../ui/button'; import { Card, CardContent } from '../ui/card'; import { Input } from '../ui/input'; import { Label } from '../ui/label'; import { resetPassword } from '../../lib/auth-client'; const logo = '/logo.png'; interface Props { onSuccess: () => void; } export function ResetPassword({ onSuccess }: Props) { const token = new URLSearchParams(window.location.search).get('token') || ''; const [password, setPassword] = useState(''); const [confirm, setConfirm] = useState(''); const [error, setError] = useState(''); const [loading, setLoading] = useState(false); const [done, setDone] = useState(false); async function handleSubmit(e: React.FormEvent) { e.preventDefault(); setError(''); if (password.length < 8) { setError('Password must be at least 8 characters'); return; } if (password !== confirm) { setError('Passwords do not match'); return; } setLoading(true); const res = await resetPassword({ newPassword: password, token }); setLoading(false); if (res.error) { setError(res.error.message || 'Failed to reset password. The link may have expired.'); } else { setDone(true); setTimeout(onSuccess, 2000); } } return (
LabWise
{done ? (

Password reset!

Redirecting you to sign in…

) : ( <>

Set new password

Choose a new password for your account.

setPassword(e.target.value)} required autoComplete="new-password" placeholder="Min. 8 characters" />
setConfirm(e.target.value)} required autoComplete="new-password" />
{error &&

{error}

}
)}
); }