2026-11-15 21:00:50 +00:00
|
|
|
|
import type { Metadata } from "next";
|
2026-11-17 11:55:08 +00:00
|
|
|
|
import Link from "next/link";
|
2026-11-15 21:00:50 +00:00
|
|
|
|
import { redirect } from "next/navigation";
|
|
|
|
|
|
|
|
|
|
|
|
import { Logo } from "@/components/SiteHeader";
|
|
|
|
|
|
import { ZodiacWheel } from "@/components/ZodiacWheel";
|
|
|
|
|
|
import { BACKEND_URL, getMe } from "@/lib/server";
|
2026-11-17 18:37:15 +00:00
|
|
|
|
import { formatDate } from "@/lib/astro";
|
|
|
|
|
|
import type { InvitationLanding, PublicConfig } from "@/lib/types";
|
2026-11-15 21:00:50 +00:00
|
|
|
|
|
|
|
|
|
|
import { GoogleLogin } from "./GoogleLogin";
|
|
|
|
|
|
|
|
|
|
|
|
export const metadata: Metadata = { title: "Belépés" };
|
|
|
|
|
|
|
|
|
|
|
|
/** Only local paths, so the login cannot redirect to another site. */
|
|
|
|
|
|
function safeTarget(value: string | string[] | undefined): string {
|
|
|
|
|
|
const v = Array.isArray(value) ? value[0] : value;
|
2026-11-16 06:37:59 +00:00
|
|
|
|
return v && v.startsWith("/") && !v.startsWith("//") ? v : "/";
|
2026-11-15 21:00:50 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2026-11-17 18:37:15 +00:00
|
|
|
|
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 }: { invitation: InvitationLanding | null }) {
|
|
|
|
|
|
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 Google-fiókoddal elfogadhatod. Érvényes: {formatDate(invitation.expires_at).replace(/\.$/, "")}-ig.
|
|
|
|
|
|
</p>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2026-11-15 21:00:50 +00:00
|
|
|
|
export default async function LoginPage({ searchParams }: { searchParams: Promise<Record<string, string | string[]>> }) {
|
2026-11-17 18:37:15 +00:00
|
|
|
|
const params = await searchParams;
|
|
|
|
|
|
const target = safeTarget(params.vissza);
|
2026-11-15 21:00:50 +00:00
|
|
|
|
if (await getMe()) redirect(target);
|
2026-11-17 18:37:15 +00:00
|
|
|
|
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),
|
|
|
|
|
|
]);
|
2026-11-15 21:00:50 +00:00
|
|
|
|
const clientId = config?.google_login.enabled ? config.google_login.client_id : null;
|
2026-11-17 18:37:15 +00:00
|
|
|
|
const inviteOnly = config?.signup_mode === "invite";
|
2026-11-15 21:00:50 +00:00
|
|
|
|
|
|
|
|
|
|
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>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
</aside>
|
|
|
|
|
|
<main className="auth-main">
|
|
|
|
|
|
<div className="auth-box">
|
|
|
|
|
|
<div className="page-head">
|
2026-11-17 18:37:15 +00:00
|
|
|
|
<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>
|
2026-11-15 21:00:50 +00:00
|
|
|
|
</div>
|
2026-11-17 18:37:15 +00:00
|
|
|
|
{rawToken && <InvitationCard invitation={inviteToken ? invitation : null} />}
|
2026-11-15 21:00:50 +00:00
|
|
|
|
{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 ? (
|
2026-11-17 18:37:15 +00:00
|
|
|
|
<GoogleLogin
|
|
|
|
|
|
clientId={clientId}
|
|
|
|
|
|
target={target}
|
|
|
|
|
|
inviteToken={invitation?.status === "pending" ? inviteToken : null}
|
|
|
|
|
|
/>
|
2026-11-15 21:00:50 +00:00
|
|
|
|
) : (
|
|
|
|
|
|
<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>
|
|
|
|
|
|
)}
|
2026-11-17 18:37:15 +00:00
|
|
|
|
<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."
|
|
|
|
|
|
: "Még nincs fiókod? Az első belépéskor létrejön."}
|
|
|
|
|
|
</p>
|
2026-11-15 21:00:50 +00:00
|
|
|
|
<p className="hint">
|
|
|
|
|
|
A belépéssel elfogadod, hogy a születési adataidat a képleted kiszámításához tároljuk. Bármikor törölheted
|
2026-11-17 11:55:08 +00:00
|
|
|
|
őket a profilodban. Részletek: <Link href="/adatvedelem">adatvédelmi tájékoztató</Link>.
|
2026-11-15 21:00:50 +00:00
|
|
|
|
</p>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
</main>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
);
|
|
|
|
|
|
}
|