import { prisma } from "@/prisma"; import { notFound, redirect } from 'next/navigation'; import { auth } from "@/auth"; import { getUser } from "@/data/user"; import { AcceptInviteButton } from "./components/acceptInviteButton" import { fetchSubscription } from "@/actions"; import { isServiceError } from "@/lib/utils"; import { SourcebotLogo } from "@/app/components/sourcebotLogo"; interface RedeemPageProps { searchParams?: { invite_id?: string; }; } interface ErrorLayoutProps { title: string; } function ErrorLayout({ title }: ErrorLayoutProps) { return (

{title}

); } export default async function RedeemPage({ searchParams }: RedeemPageProps) { const invite_id = searchParams?.invite_id; if (!invite_id) { notFound(); } const invite = await prisma.invite.findUnique({ where: { id: invite_id }, }); if (!invite) { return ( ); } const session = await auth(); let user = undefined; if (session) { user = await getUser(session.user.id); } // Auth case if (user) { if (user.email !== invite.recipientEmail) { return ( ) } else { const org = await prisma.org.findUnique({ where: { id: invite.orgId }, }); if (!org) { return ( ) } return (

You have been invited to org {org.name}

); } } else { redirect(`/login?callbackUrl=${encodeURIComponent(`/redeem?invite_id=${invite_id}`)}`); } }