auth: e-mail + password login with e-mailed password links
CI / test (push) Failing after 1m39s
CI / build (push) Skipped
CI / deploy (push) Skipped

Sign-up asks no password: a link goes to the address and the password is
set there (also for forgotten passwords), by whoever opens the mailbox.
So nobody can register a password for someone else's address, and linking
Google or Apple to an account with the same address stays safe. Opening
the link confirms the address, ends other sessions and logs in.

Sign-up answers alike for registered addresses (the owner gets an
'account exists' link), links are limited to one per kind a minute and
five an hour, and unconfirmed password accounts cannot log in.
Frontend: login form with sign-up and forgotten password next to the
social buttons, and the /jelszo page for the link. Still behind
PASSWORD_LOGIN (off on prod).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_012vLHzh5qUhFtmJhzkcTbXL
This commit is contained in:
feco
2026-11-21 18:24:48 +00:00
co-authored by Claude Opus 5.5
parent a63f8f9928
commit 7d6a6c3d92
11 changed files with 651 additions and 192 deletions
+53
View File
@@ -0,0 +1,53 @@
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>
);
}