// ─────────────────────────────────────────────── // Join (Invite) Page (/join/[token]) // ─────────────────────────────────────────────── // Route: /join/:token // Purpose: Server component that validates an // invite token. If the token is a UUID (room // ID), it redirects directly to /call/:token. // Otherwise it queries the DB for an SMS-style // invite and shows a "You're Invited!" landing // page with the caller's phone number. // Layout: Centered card with invite details and // a "Create Account" CTA. // Error states: invalid token, expired token. // ─────────────────────────────────────────────── import { query } from "@/lib/db" import { redirect } from "next/navigation" interface Props { params: Promise<{ token: string }> } /** * ErrorPage * ───────── * Shared inline component for rendering error * states (invalid / expired) with the same * card styling. * * @param message - The error message to display. * @returns A centered error card. */ function ErrorPage({ message }: { message: string }) { return (

{message}

) } /** * JoinPage * ──────── * Validates an invite token. UUID tokens redirect * directly into a call room. DB-backed tokens * (from SMS invites) show a landing page with * the inviter's contact info and a register CTA. * * @param params - Route params containing the token. * @returns An error page, redirect, or invite page. */ export default async function JoinPage({ params }: Props) { const { token } = await params // ── UUID tokens → direct call room redirect ── const UUID_REGEX = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i if (UUID_REGEX.test(token)) { redirect(`/call/${token}`) } // ── Look up SMS invite token in DB ── const result = await query( `SELECT phone, created_at, expires_at FROM invites WHERE token = $1 LIMIT 1`, [token], ) if (result.rows.length === 0) { return } const invite = result.rows[0] // ── Check expiration ── if (new Date(invite.expires_at) <= new Date()) { return } return (

You're Invited!

Someone wants to connect with you on our platform.

{/* ── Inviter's contact number ── */}

Contact Number

{invite.phone}

Create an account to start making free voice calls to this person and others on the platform.

{/* ── Registration CTA ── */} Create Account
) }