- Login copy describes the event CRM instead of orders and payouts.
- Role dialog has no parent field; the role routes require a trimmed name and forward only {name}.
- New-user banner says a temporary password was emailed; TEMP_PASSWORD_NOT_SENT shows a message and a link back to users.
- Username is read-only when editing.
- Password hint and an 8-character minimum match the backend admin password rules.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01EFUzfj5akPxyikzGc2iAHM
97 lines
3.6 KiB
TypeScript
97 lines
3.6 KiB
TypeScript
"use client";
|
|
|
|
import { useState } from "react";
|
|
import { Loader2 } from "lucide-react";
|
|
import { useRouter } from "next/navigation";
|
|
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 { useAdminAuth } from "@/app/lib/AdminAuthContext";
|
|
import { useT } from "@/app/lib/i18n/MessagesProvider";
|
|
import PoweredBy from "@/app/components/app/PoweredBy";
|
|
|
|
// First sign-in: login answered resetPasswordRequired (the account is still on the temporary
|
|
// password an admin set), so the user must choose their own before reaching the portal.
|
|
export default function ResetPasswordPage() {
|
|
const router = useRouter();
|
|
const { refresh } = useAdminAuth();
|
|
const t = useT();
|
|
const [newPassword, setNewPassword] = useState("");
|
|
const [confirmPassword, setConfirmPassword] = useState("");
|
|
const [error, setError] = useState<string | null>(null);
|
|
const [submitting, setSubmitting] = useState(false);
|
|
|
|
async function handleSubmit(event: React.FormEvent<HTMLFormElement>) {
|
|
event.preventDefault();
|
|
setError(null);
|
|
if (!newPassword || !confirmPassword) {
|
|
setError("ResetAllRequired");
|
|
return;
|
|
}
|
|
if (newPassword !== confirmPassword) {
|
|
setError("ResetMismatch");
|
|
return;
|
|
}
|
|
setSubmitting(true);
|
|
try {
|
|
await apiPost("/api/auth/first-login", { newPassword });
|
|
await refresh();
|
|
router.push("/");
|
|
} catch (err) {
|
|
setError(err instanceof Error ? err.message : "ResetFailed");
|
|
} finally {
|
|
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("ResetTitle")}</CardTitle>
|
|
<CardDescription>{t("ResetChooseIntro")}</CardDescription>
|
|
</CardHeader>
|
|
<CardContent>
|
|
{error && <ErrorState message={t(error)} className="mb-4" />}
|
|
<form onSubmit={handleSubmit} className="space-y-4" noValidate>
|
|
<div className="space-y-1.5">
|
|
<Label htmlFor="newPassword">{t("ResetNewPassword")}</Label>
|
|
<Input
|
|
id="newPassword"
|
|
type="password"
|
|
autoComplete="new-password"
|
|
value={newPassword}
|
|
onChange={(e) => setNewPassword(e.target.value)}
|
|
disabled={submitting}
|
|
aria-describedby="newPasswordRules"
|
|
/>
|
|
<p id="newPasswordRules" className="text-sm text-muted-foreground">{t("AdminPasswordHint")}</p>
|
|
</div>
|
|
<div className="space-y-1.5">
|
|
<Label htmlFor="confirmPassword">{t("ResetConfirmPassword")}</Label>
|
|
<Input
|
|
id="confirmPassword"
|
|
type="password"
|
|
autoComplete="new-password"
|
|
value={confirmPassword}
|
|
onChange={(e) => setConfirmPassword(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("ResetSubmit")}
|
|
</Button>
|
|
</form>
|
|
</CardContent>
|
|
</Card>
|
|
<div className="text-center">
|
|
<PoweredBy />
|
|
</div>
|
|
</div>
|
|
);
|
|
}
|