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 { 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 { 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 = { 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 (

Ez a meghívólink érvénytelen. Ellenőrizd, hogy a teljes linket nyitottad-e meg a levélből.

); } if (invitation.status !== "pending") { return (

{CLOSED[invitation.status]}

); } return (
Meghívó

{invitation.inviter_name ? {invitation.inviter_name} : "Valaki"} meghívott a Sorsfonalakra.

{invitation.message &&
{invitation.message}
}

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.

); } export default async function LoginPage({ searchParams }: { searchParams: Promise> }) { 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 (

{rawToken ? "Meghívó" : "Belépés"}

{rawToken ? "Lépj be, és már kezdheted is." : "Üdv újra! Lépj be a fiókodba."}

{rawToken && ( )} {config === null ? (

A szerver most nem érhető el. Próbáld újra egy kicsit később.

) : clientId || password ? ( <> {clientId && (
{appleId && ( )}
)} {clientId && password && (
vagy
)} {password && ( )} ) : (

A Google-belépés még nincs beállítva (a backend GOOGLE_CLIENT_IDS változója üres).

)}

{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."}

A belépéssel elfogadod az általános szerződési feltételeket, é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:{" "} adatvédelmi tájékoztató.

); }