import { createFileRoute, Link, useSearch } from '@tanstack/react-router' import { useState } from 'react' import { Button } from '@/components/ui/button' import { Input } from '@/components/ui/input' import { Label } from '@/components/ui/label' import { authApi } from '@/lib/api' import { RugLogo } from '@/components/brand/RugLogo' export const Route = createFileRoute('/reset-password')({ component: ResetPasswordPage, validateSearch: (search: Record) => ({ token: (search.token as string) ?? '', }), }) function ResetPasswordPage() { const { token } = useSearch({ from: '/reset-password' }) const [password, setPassword] = useState('') const [confirmPassword, setConfirmPassword] = useState('') const [submitting, setSubmitting] = useState(false) const [success, setSuccess] = useState(false) const [error, setError] = useState(null) const passwordsMatch = password === confirmPassword const passwordLongEnough = password.length >= 8 const handleSubmit = async (e: React.FormEvent) => { e.preventDefault() if (!password || !confirmPassword || !passwordsMatch || !passwordLongEnough) return setSubmitting(true) setError(null) try { await authApi.resetPassword(token, password) setSuccess(true) } catch (err: unknown) { const msg = (err as { response?: { data?: { detail?: string } } })?.response?.data?.detail ?? 'Something went wrong. Please try again.' setError(msg) } finally { setSubmitting(false) } } if (!token) { return (

Invalid reset link. No token provided.

Back to Sign In
) } return (
{/* Logo / branding */}

Set New Password

Choose a strong password

{success ? (

Password has been reset successfully.

When you sign in, you will be guided through a one-time security upgrade to zero-knowledge authentication. Your password will never be stored on the server.

Go to Sign In
) : (
void handleSubmit(e)} className="space-y-4">
{ setPassword(e.target.value) if (error) setError(null) }} placeholder="Minimum 8 characters" autoComplete="new-password" autoFocus required minLength={8} /> {password && !passwordLongEnough && (

Must be at least 8 characters

)}
{ setConfirmPassword(e.target.value) if (error) setError(null) }} placeholder="Re-enter password" autoComplete="new-password" required minLength={8} /> {confirmPassword && !passwordsMatch && (

Passwords do not match

)}
{error && (

{error}

)} Back to Sign In
)}
) }