/forgot-password always shows the same message; the route never forwards upstream errors or a token. /api/admin/me now returns id and username so the user form can lock the Active switch on your own account. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01EFUzfj5akPxyikzGc2iAHM
84 lines
3.4 KiB
TypeScript
84 lines
3.4 KiB
TypeScript
"use client";
|
|
|
|
import { useState } from "react";
|
|
import Link from "next/link";
|
|
import { Loader2 } from "lucide-react";
|
|
import { Button } from "@/app/components/ui/button";
|
|
import { Card, CardContent, CardDescription, CardHeader, CardTitle } from "@/app/components/ui/card";
|
|
import { Input } from "@/app/components/ui/input";
|
|
import { Label } from "@/app/components/ui/label";
|
|
import { ErrorState } from "@/app/components/ui/states";
|
|
import { apiPost } from "@/app/lib/clientApi";
|
|
import { useT } from "@/app/lib/i18n/MessagesProvider";
|
|
import PoweredBy from "@/app/components/app/PoweredBy";
|
|
|
|
// Public "email me a temporary password" form. Whatever happens (match, no match, server or network
|
|
// failure) the visitor sees the same message, so the page never reveals whether an account exists.
|
|
export default function ForgotPasswordPage() {
|
|
const t = useT();
|
|
const [username, setUsername] = useState("");
|
|
const [email, setEmail] = useState("");
|
|
const [required, setRequired] = useState(false);
|
|
const [submitting, setSubmitting] = useState(false);
|
|
const [sent, setSent] = useState(false);
|
|
|
|
async function handleSubmit(event: React.FormEvent<HTMLFormElement>) {
|
|
event.preventDefault();
|
|
if (!username.trim() || !email.trim()) {
|
|
setRequired(true);
|
|
return;
|
|
}
|
|
setRequired(false);
|
|
setSubmitting(true);
|
|
try {
|
|
await apiPost("/api/auth/forgot-password", { username: username.trim(), email: email.trim() });
|
|
} catch {
|
|
// Deliberately ignored: a failure must look the same as success.
|
|
}
|
|
setSent(true);
|
|
setSubmitting(false);
|
|
}
|
|
|
|
return (
|
|
<div className="flex min-h-svh flex-col items-center justify-center gap-4 bg-background p-4">
|
|
<Card className="w-full max-w-sm">
|
|
<CardHeader className="gap-2">
|
|
<CardTitle className="text-lg">{t("ForgotTitle")}</CardTitle>
|
|
<CardDescription>{t("ForgotIntro")}</CardDescription>
|
|
</CardHeader>
|
|
<CardContent className="space-y-4">
|
|
{sent ? (
|
|
<p role="status" className="text-sm">{t("ForgotSent")}</p>
|
|
) : (
|
|
<>
|
|
{required && <ErrorState message={t("ForgotRequired")} />}
|
|
<form onSubmit={handleSubmit} className="space-y-4" noValidate>
|
|
<div className="space-y-1.5">
|
|
<Label htmlFor="username">{t("Username")}</Label>
|
|
<Input id="username" autoComplete="username" required value={username}
|
|
onChange={(e) => setUsername(e.target.value)} disabled={submitting} />
|
|
</div>
|
|
<div className="space-y-1.5">
|
|
<Label htmlFor="email">{t("Email")}</Label>
|
|
<Input id="email" type="email" autoComplete="email" required value={email}
|
|
onChange={(e) => setEmail(e.target.value)} disabled={submitting} />
|
|
</div>
|
|
<Button type="submit" className="w-full" disabled={submitting}>
|
|
{submitting && <Loader2 aria-hidden="true" className="size-4 animate-spin" />}
|
|
{t("ForgotSubmit")}
|
|
</Button>
|
|
</form>
|
|
</>
|
|
)}
|
|
<Link href="/login" className="block text-sm text-muted-foreground underline-offset-4 hover:underline">
|
|
{t("ForgotBack")}
|
|
</Link>
|
|
</CardContent>
|
|
</Card>
|
|
<div className="text-center">
|
|
<PoweredBy />
|
|
</div>
|
|
</div>
|
|
);
|
|
}
|