Password Reset Example
A two-step password reset flow with email verification.
Step 1: Request Reset
First, users enter their email to request a password reset link.
{
"type": "password-reset-request",
"title": "Reset your password",
"description": "Enter your email and we'll send you a reset link",
"fields": [
{
"name": "email",
"type": "email",
"label": "Email Address",
"placeholder": "you@example.com",
"required": true
}
],
"submit": "Send Reset Link",
"footer": {
"text": "Remember your password?",
"link": {
"text": "Sign in",
"href": "/login"
}
}
}Step 2: Reset Password
After clicking the email link, users can set a new password.
{
"type": "password-reset",
"title": "Create new password",
"description": "Enter a strong password for your account",
"fields": [
{
"name": "password",
"type": "password",
"label": "New Password",
"placeholder": "Enter your new password",
"required": true,
"minLength": 8
},
{
"name": "confirmPassword",
"type": "password",
"label": "Confirm Password",
"placeholder": "Re-enter your new password",
"required": true,
"matchField": "password"
}
],
"submit": "Reset Password"
}Implementation
// app/reset-password/page.tsx
import { AuthForm } from "declarative-auth-forms"
import requestSchema from "./request-schema.json"
export default function RequestResetPage() {
const handleRequest = async (data: any) => {
const response = await fetch("/api/auth/reset-password/request", {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify(data),
})
if (response.ok) {
// Show success message
alert("Check your email for a reset link")
}
}
return (
<div className="min-h-screen flex items-center justify-center p-4">
<AuthForm
schema={requestSchema}
onSubmit={handleRequest}
/>
</div>
)
}
// app/reset-password/confirm/page.tsx
import { AuthForm } from "declarative-auth-forms"
import resetSchema from "./reset-schema.json"
export default function ConfirmResetPage() {
const handleReset = async (data: any) => {
const token = new URLSearchParams(window.location.search).get("token")
const response = await fetch("/api/auth/reset-password/confirm", {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({ ...data, token }),
})
if (response.ok) {
window.location.href = "/login"
}
}
return (
<div className="min-h-screen flex items-center justify-center p-4">
<AuthForm
schema={resetSchema}
onSubmit={handleReset}
/>
</div>
)
}Security Considerations
- Reset tokens should expire after a short period (e.g., 1 hour)
- Tokens should be single-use only
- Always validate tokens on the server
- Don't reveal whether an email exists in the system
- Rate limit reset requests to prevent abuse
Email Template
Your password reset email should include:
- Clear subject line: "Reset your password"
- Explanation of why they received the email
- Prominent reset button/link
- Token expiration time
- Instructions to ignore if they didn't request it