Custom auth stack: bcryptjs password hashing (cost 10, GoTrue-compatible), jose JWT session cookies (edge-safe, 8hr TTL), new API routes for login/logout/reset/change-password, middleware rewritten to JWT-only verification with no DB access. All 38 protected pages and API routes migrated from supabase.auth.getUser() to getSession(). Supabase .from() queries retained for Phase 4. lib/db/index.ts refactored to lazy Proxy singleton to avoid module-level throw during Next.js build. tsc: clean, build: clean, tests: 4/4 passed Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
80 lines
2.5 KiB
TypeScript
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'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-gray-300 rounded-md 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 rounded-md 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>
|
|
)
|
|
}
|