import { redirect } from "next/navigation"; import { cookies } from "next/headers"; import { prisma } from "@/lib/prisma"; interface JoinPageProps { searchParams: Promise<{ code?: string; error?: string }>; } async function submitCode(formData: FormData) { "use server"; const code = (formData.get("code") as string | null)?.trim().toUpperCase(); if (!code) redirect("/join?error=missing"); const invite = await prisma.inviteCode.findUnique({ where: { code } }); if (!invite || invite.usedById || invite.revoked) { redirect(`/join?error=invalid`); } const cookieStore = await cookies(); cookieStore.set("pf_invite", code, { httpOnly: true, secure: process.env.NODE_ENV === "production", sameSite: "lax", maxAge: 60 * 60, path: "/", }); redirect("/sign-up"); } export default async function JoinPage({ searchParams }: JoinPageProps) { const { code: codeParam, error } = await searchParams; // Code in URL → hand off to route handler which can set cookies if (codeParam) { redirect(`/api/auth/set-invite?code=${encodeURIComponent(codeParam)}`); } const errorMessage = error === "invalid" ? "Ungültiger oder bereits verwendeter Einladungscode." : error === "missing" ? "Bitte gib einen Einladungscode ein." : null; return (
{/* Logo / brand */}

PawFeed

Alpha · Nur auf Einladung

Einladungscode eingeben

PawFeed ist aktuell nur per Einladung zugänglich. Du brauchst einen Code von einem Mitglied.

{errorMessage && (

{errorMessage}

)}

Noch kein Code? Bitte einen Freund, der PawFeed-Mitglied ist.

); }