54 lines
1.8 KiB
TypeScript
54 lines
1.8 KiB
TypeScript
import type { Metadata } from "next";
|
|||
|
|
import Link from "next/link";
|
||
|
|
|
||
|
|
import { Logo } from "@/components/SiteHeader";
|
||
|
|
import { BACKEND_URL } from "@/lib/server";
|
||
|
|
import type { PublicConfig } from "@/lib/types";
|
||
|
|
|
||
|
|
import { SetPasswordForm } from "./SetPasswordForm";
|
||
|
|
|
||
|
|
export const metadata: Metadata = { title: "Jelszó megadása", robots: { index: false } };
|
||
|
|
|
||
|
|
async function minLength(): Promise<number> {
|
||
|
|
try {
|
||
|
|
const res = await fetch(`${BACKEND_URL}/v1/config`, { cache: "no-store" });
|
||
|
|
if (res.ok) return ((await res.json()) as PublicConfig).password_min_length;
|
||
|
|
} catch {
|
||
|
|
// backend down: the form still works, the backend checks the length
|
||
|
|
}
|
||
|
|
return 10;
|
||
|
|
}
|
||
|
|
|
||
|
|
/** The page of the e-mailed password link (sign-up and forgotten password). */
|
||
|
|
export default async function SetPasswordPage({
|
||
|
|
searchParams,
|
||
|
|
}: {
|
||
|
|
searchParams: Promise<Record<string, string | string[]>>;
|
||
|
|
}) {
|
||
|
|
const params = await searchParams;
|
||
|
|
const raw = Array.isArray(params.token) ? params.token[0] : params.token;
|
||
|
|
const token = raw && /^[A-Za-z0-9_-]{8,200}$/.test(raw) ? raw : null;
|
||
|
|
|
||
|
|
return (
|
||
|
|
<div className="auth">
|
||
|
|
<main className="auth-main">
|
||
|
|
<div className="auth-box">
|
||
|
|
<Logo />
|
||
|
|
<div className="page-head">
|
||
|
|
<h1 style={{ fontSize: 40 }}>Jelszó megadása</h1>
|
||
|
|
<p className="muted">Add meg a jelszavad, amellyel ezentúl belépsz.</p>
|
||
|
|
</div>
|
||
|
|
{token ? (
|
||
|
|
<SetPasswordForm token={token} minLength={await minLength()} />
|
||
|
|
) : (
|
||
|
|
<p className="msg msg-error" role="alert">
|
||
|
|
Hiányos a link. Nyisd meg a teljes linket a levélből, vagy kérj újat a{" "}
|
||
|
|
<Link href="/belepes?mod=elfelejtett">belépésnél</Link>.
|
||
|
|
</p>
|
||
|
|
)}
|
||
|
|
</div>
|
||
|
|
</main>
|
||
|
|
</div>
|
||
|
|
);
|
||
|
|
}
|