-
Notifications
You must be signed in to change notification settings - Fork 112
Expand file tree
/
Copy pathpage.tsx
More file actions
80 lines (72 loc) · 2.34 KB
/
Copy pathpage.tsx
File metadata and controls
80 lines (72 loc) · 2.34 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
"use client";
import { useState } from "react";
import Link from "next/link";
export default function ForgotPasswordPage() {
const [email, setEmail] = useState("");
const [submitted, setSubmitted] = useState(false);
const [loading, setLoading] = useState(false);
const [error, setError] = useState("");
const handleSubmit = async (e: React.FormEvent) => {
e.preventDefault();
setLoading(true);
setError("");
const res = await fetch("/api/auth/forgot-password", {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({ email }),
});
const data = await res.json();
setLoading(false);
if (!res.ok) {
setError(data.error || "Something went wrong");
} else {
setSubmitted(true);
}
};
if (submitted) {
return (
<div className="flex min-h-screen items-center justify-center">
<div className="text-center space-y-4">
<h1 className="text-2xl font-bold">Check your email</h1>
<p className="text-muted-foreground">
If that email exists, we've sent a password reset link.
</p>
<Link href="/login" className="text-sm hover:underline">
Back to login
</Link>
</div>
</div>
);
}
return (
<div className="flex min-h-screen items-center justify-center">
<div className="w-full max-w-md space-y-6 p-6">
<h1 className="text-2xl font-bold">Forgot Password</h1>
<p className="text-muted-foreground">
Enter your email and we'll send you a reset link.
</p>
<form onSubmit={handleSubmit} className="space-y-4">
<input
type="email"
placeholder="Enter your email"
value={email}
onChange={(e) => setEmail(e.target.value)}
required
className="w-full border rounded px-3 py-2"
/>
{error && <p className="text-red-500 text-sm">{error}</p>}
<button
type="submit"
disabled={loading}
className="w-full bg-black text-white py-2 rounded hover:bg-gray-800"
>
{loading ? "Sending..." : "Send Reset Link"}
</button>
</form>
<Link href="/login" className="text-sm hover:underline">
Back to login
</Link>
</div>
</div>
);
}