| 15 | } |
| 16 | |
| 17 | export default async function InvitePage(props: InvitePageProps) { |
| 18 | const searchParams = await props.searchParams; |
| 19 | const org = await __unsafePrisma.org.findUnique({ where: { id: SINGLE_TENANT_ORG_ID } }); |
| 20 | if (!org || !org.isOnboarded) { |
| 21 | return redirect("/onboard"); |
| 22 | } |
| 23 | |
| 24 | const inviteLinkId = searchParams.id; |
| 25 | if (!org.inviteLinkEnabled || !inviteLinkId || org.inviteLinkId !== inviteLinkId) { |
| 26 | return notFound(); |
| 27 | } |
| 28 | |
| 29 | const session = await auth(); |
| 30 | if (!session) { |
| 31 | return <WelcomeCard inviteLinkId={inviteLinkId} />; |
| 32 | } |
| 33 | |
| 34 | const membership = await __unsafePrisma.userToOrg.findUnique({ |
| 35 | where: { |
| 36 | orgId_userId: { |
| 37 | orgId: org.id, |
| 38 | userId: session.user.id |
| 39 | } |
| 40 | } |
| 41 | }); |
| 42 | |
| 43 | // If already a member, redirect to the organization |
| 44 | if (membership) { |
| 45 | redirect(`/`); |
| 46 | } |
| 47 | |
| 48 | // User is logged in but not a member, show join invitation |
| 49 | return ( |
| 50 | <div className="min-h-screen flex items-center justify-center p-6"> |
| 51 | <LogoutEscapeHatch className="absolute top-0 right-0 p-6" /> |
| 52 | <JoinOrganizationCard inviteLinkId={inviteLinkId} /> |
| 53 | </div> |
| 54 | ); |
| 55 | } |
| 56 | |
| 57 | function WelcomeCard({ inviteLinkId }: { inviteLinkId: string; }) { |
| 58 | return ( |