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 { 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; return v && v.startsWith("/") && !v.startsWith("//") ? 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 }: { invitation: InvitationLanding | null }) { 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 Google-fiókoddal 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 inviteOnly = config?.signup_mode === "invite"; 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 ? ( ) : (

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." : "Még nincs fiókod? Az első belépéskor létrejön."}

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 őket a profilodban. Részletek: adatvédelmi tájékoztató.

); }