The share page stores nothing in the browser any more: the shared link that brought a visitor travels in its login link (/belepes?ref=...) to the Google, Apple and password sign-up. The backend counts the same visitor of a link once in half an hour, instead of a sessionStorage flag. The public birth chart scrolls to the drawn chart after a calculation and when coming back to the page. Tabs scrolled to themselves on every re-render of their parent when the address had a tab (#bolygok); they now react only to the tab ids and hash changes. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_012vLHzh5qUhFtmJhzkcTbXL
184 lines
7.6 KiB
TypeScript
184 lines
7.6 KiB
TypeScript
import type { Metadata } from "next";
|
||
import Link from "next/link";
|
||
import { redirect } from "next/navigation";
|
||
|
||
import { Logo } from "@/components/SiteHeader";
|
||
import { ZodiacWheel } from "@/components/ZodiacWheel";
|
||
import { BACKEND_URL, getMe } from "@/lib/server";
|
||
import { formatDate } from "@/lib/astro";
|
||
import type { InvitationLanding, PublicConfig } from "@/lib/types";
|
||
|
||
import { AppleLogin } from "./AppleLogin";
|
||
import { GoogleLogin } from "./GoogleLogin";
|
||
import { PasswordLogin } from "./PasswordLogin";
|
||
|
||
export const metadata: Metadata = { title: "Belépés" };
|
||
|
||
/**
|
||
* Only local paths, so the login cannot redirect to another site: one leading
|
||
* slash, no backslash (browsers read "/\\evil.com" as "//evil.com") and no
|
||
* control characters.
|
||
*/
|
||
function safeTarget(value: string | string[] | undefined): string {
|
||
const v = Array.isArray(value) ? value[0] : value;
|
||
return v && /^\/(?![/\\])[^\\\u0000-\u001f]*$/.test(v) ? v : "/";
|
||
}
|
||
|
||
async function loadConfig(): Promise<PublicConfig | null> {
|
||
try {
|
||
const res = await fetch(`${BACKEND_URL}/v1/config`, { cache: "no-store" });
|
||
return res.ok ? ((await res.json()) as PublicConfig) : null;
|
||
} catch {
|
||
return null;
|
||
}
|
||
}
|
||
|
||
async function loadInvitation(token: string): Promise<InvitationLanding | null> {
|
||
try {
|
||
const res = await fetch(`${BACKEND_URL}/v1/public/invitations/${encodeURIComponent(token)}`, { cache: "no-store" });
|
||
return res.ok ? ((await res.json()) as InvitationLanding) : null;
|
||
} catch {
|
||
return null;
|
||
}
|
||
}
|
||
|
||
const CLOSED: Record<string, string> = {
|
||
accepted: "Ezt a meghívót már felhasználták. Ha a tiéd volt, egyszerűen lépj be ugyanazzal a Google-fiókkal.",
|
||
expired: "Ez a meghívó lejárt. Kérj újat attól, aki meghívott.",
|
||
revoked: "Ezt a meghívót visszavonták.",
|
||
};
|
||
|
||
/** The invitation the visitor came with: who sent it and what they wrote. */
|
||
function InvitationCard({
|
||
invitation,
|
||
apple,
|
||
password,
|
||
}: {
|
||
invitation: InvitationLanding | null;
|
||
apple: boolean;
|
||
password: boolean;
|
||
}) {
|
||
if (!invitation) {
|
||
return (
|
||
<p className="msg msg-error" role="alert">
|
||
Ez a meghívólink érvénytelen. Ellenőrizd, hogy a teljes linket nyitottad-e meg a levélből.
|
||
</p>
|
||
);
|
||
}
|
||
if (invitation.status !== "pending") {
|
||
return (
|
||
<p className="msg msg-error" role="alert">
|
||
{CLOSED[invitation.status]}
|
||
</p>
|
||
);
|
||
}
|
||
return (
|
||
<div className="card invite-card">
|
||
<span className="eyebrow">Meghívó</span>
|
||
<p style={{ margin: 0 }}>
|
||
{invitation.inviter_name ? <strong>{invitation.inviter_name}</strong> : "Valaki"} meghívott a Sorsfonalakra.
|
||
</p>
|
||
{invitation.message && <blockquote className="invite-quote">{invitation.message}</blockquote>}
|
||
<p className="hint" style={{ margin: 0 }}>
|
||
Bármelyik {apple ? "Google- vagy Apple-fiókoddal" : "Google-fiókoddal"}
|
||
{password ? ", vagy e-mail-címmel regisztrálva" : ""} elfogadhatod. Érvényes:{" "}
|
||
{formatDate(invitation.expires_at).replace(/\.$/, "")}-ig.
|
||
</p>
|
||
</div>
|
||
);
|
||
}
|
||
|
||
export default async function LoginPage({ searchParams }: { searchParams: Promise<Record<string, string | string[]>> }) {
|
||
const params = await searchParams;
|
||
const target = safeTarget(params.vissza);
|
||
if (await getMe()) redirect(target);
|
||
const rawToken = Array.isArray(params.meghivo) ? params.meghivo[0] : params.meghivo;
|
||
const inviteToken = rawToken && /^[A-Za-z0-9_-]{8,200}$/.test(rawToken) ? rawToken : null;
|
||
const [config, invitation] = await Promise.all([
|
||
loadConfig(),
|
||
inviteToken ? loadInvitation(inviteToken) : Promise.resolve(null),
|
||
]);
|
||
const clientId = config?.google_login.enabled ? config.google_login.client_id : null;
|
||
const appleId = config?.apple_login?.enabled ? config.apple_login.client_id : null;
|
||
const pendingInvite = invitation?.status === "pending" ? inviteToken : null;
|
||
// The shared link that brought the visitor (from its login button), for the sharer's reward.
|
||
const rawRef = Array.isArray(params.ref) ? params.ref[0] : params.ref;
|
||
const referral = rawRef && /^[A-Za-z0-9_-]{4,64}$/.test(rawRef) ? rawRef : null;
|
||
const inviteOnly = config?.signup_mode === "invite";
|
||
const password = config?.password_login === true;
|
||
const mod = Array.isArray(params.mod) ? params.mod[0] : params.mod;
|
||
const initialMode = mod === "elfelejtett" ? "forgot" : mod === "regisztracio" || rawToken ? "register" : "login";
|
||
|
||
return (
|
||
<div className="auth">
|
||
<aside className="auth-aside">
|
||
<Logo />
|
||
<ZodiacWheel className="wheel" />
|
||
<div className="row" style={{ flexDirection: "column", alignItems: "flex-start", gap: 10, maxWidth: 460 }}>
|
||
<p className="tagline">Ahol a csillagok összekötnek.</p>
|
||
<p className="muted" style={{ fontSize: 16 }}>
|
||
Születési képlet, szinasztria és közösség – egy helyen.
|
||
</p>
|
||
<p className="ai-line" style={{ fontSize: 15 }}>
|
||
Részletes, személyre szóló elemzések a legfejlettebb AI-modellekkel: percek alatt, egy személyes konzultáció
|
||
árának töredékéért.
|
||
</p>
|
||
</div>
|
||
</aside>
|
||
<main className="auth-main">
|
||
<div className="auth-box">
|
||
<div className="page-head">
|
||
<h1 style={{ fontSize: 44 }}>{rawToken ? "Meghívó" : "Belépés"}</h1>
|
||
<p className="muted">{rawToken ? "Lépj be, és már kezdheted is." : "Üdv újra! Lépj be a fiókodba."}</p>
|
||
</div>
|
||
{rawToken && (
|
||
<InvitationCard invitation={inviteToken ? invitation : null} apple={appleId !== null} password={password} />
|
||
)}
|
||
{config === null ? (
|
||
<p className="msg msg-error" role="alert">
|
||
A szerver most nem érhető el. Próbáld újra egy kicsit később.
|
||
</p>
|
||
) : clientId || password ? (
|
||
<>
|
||
{clientId && (
|
||
<div className="field" style={{ gap: 12 }}>
|
||
<GoogleLogin clientId={clientId} target={target} inviteToken={pendingInvite} referral={referral} />
|
||
{appleId && (
|
||
<AppleLogin clientId={appleId} target={target} inviteToken={pendingInvite} referral={referral} />
|
||
)}
|
||
</div>
|
||
)}
|
||
{clientId && password && (
|
||
<div className="auth-or" role="separator">
|
||
<span>vagy</span>
|
||
</div>
|
||
)}
|
||
{password && (
|
||
<PasswordLogin target={target} inviteToken={pendingInvite} referral={referral} initialMode={initialMode} />
|
||
)}
|
||
</>
|
||
) : (
|
||
<p className="msg msg-error" role="alert">
|
||
A Google-belépés még nincs beállítva (a backend <code>GOOGLE_CLIENT_IDS</code> változója üres).
|
||
</p>
|
||
)}
|
||
<p className="auth-foot">
|
||
{rawToken
|
||
? "A fiókod az első belépéskor jön létre."
|
||
: inviteOnly
|
||
? "Az oldal jelenleg meghívásos: új fiók csak meghívóval jön létre."
|
||
: password
|
||
? "Google- vagy Apple-fiókkal az első belépéskor létrejön a fiókod."
|
||
: "Még nincs fiókod? Az első belépéskor létrejön."}
|
||
</p>
|
||
<p className="hint">
|
||
A belépéssel elfogadod az <Link href="/aszf">általános szerződési feltételeket</Link>, és hogy a születési
|
||
adataidat a képleted kiszámításához tároljuk. Bármikor törölheted őket a profilodban. Részletek:{" "}
|
||
<Link href="/adatvedelem">adatvédelmi tájékoztató</Link>.
|
||
</p>
|
||
</div>
|
||
</main>
|
||
</div>
|
||
);
|
||
}
|