Files
ims/app/(auth)/forgot-password/page.tsx
T

80 lines
2.5 KiB
TypeScript

'use client'
import { useState } from 'react'
import Link from 'next/link'
export default function ForgotPasswordPage() {
const [email, setEmail] = useState('')
const [loading, setLoading] = useState(false)
const [submitted, setSubmitted] = useState(false)
async function handleSubmit(e: React.FormEvent) {
e.preventDefault()
if (!email) return
setLoading(true)
await fetch('/api/auth/reset-request', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ email }),
})
setLoading(false)
// Always show "check your email" regardless of response (silent for non-existent users)
setSubmitted(true)
}
if (submitted) {
return (
<div className="flex min-h-screen items-center justify-center bg-gray-50 px-4">
<div className="w-full max-w-sm space-y-4 text-center">
<h1 className="text-2xl font-bold text-gray-900">Check your email</h1>
<p className="text-sm text-gray-500">
If an account exists for <strong>{email}</strong>, a password reset link has been sent.
</p>
<Link href="/login" className="text-sm text-blue-600 hover:underline">
Back to sign in
</Link>
</div>
</div>
)
}
return (
<div className="flex min-h-screen items-center justify-center bg-gray-50 px-4">
<form onSubmit={handleSubmit} className="flex flex-col gap-4 w-full max-w-sm">
<div className="text-center">
<h1 className="text-2xl font-bold">Reset password</h1>
<p className="text-sm text-gray-500 mt-1">
Enter your email and we&apos;ll send a reset link.
</p>
</div>
<input
type="email"
placeholder="Email"
value={email}
onChange={e => setEmail(e.target.value)}
required
autoComplete="email"
className="border border-divider px-3 py-2 text-sm focus:outline-none focus:ring-2 focus:ring-blue-500"
/>
<button
type="submit"
disabled={loading}
className="bg-blue-600 hover:bg-blue-700 text-white font-medium py-2 disabled:opacity-50 transition-colors"
>
{loading ? 'Sending…' : 'Send reset link'}
</button>
<p className="text-center text-sm text-gray-500">
<Link href="/login" className="text-blue-600 hover:underline">
Back to sign in
</Link>
</p>
</form>
</div>
)
}