import { redirect } from "next/navigation" import { AlertCircle, ShieldCheck } from "lucide-react" import { applyHandoff } from "@/modules/auth/auth.actions" type SearchParams = { ws?: string; api?: string } export default async function ActivatePage(props: { params: Promise<{ token: string }> searchParams: Promise }) { const { token } = await props.params const { ws, api } = await props.searchParams if (!ws || !api) { return ( ) } let parsed: URL try { parsed = new URL(api) if (parsed.protocol !== "http:" && parsed.protocol !== "https:") { throw new Error("Backend URL must be http(s).") } } catch { return ( ) } const endpoint = `${parsed.toString().replace(/\/$/, "")}/api/saas/handoff/exchange` let response: Response try { response = await fetch(endpoint, { method: "POST", cache: "no-store", headers: { "Content-Type": "application/json", Accept: "application/json", "X-Workspace-UUID": ws, }, body: JSON.stringify({ handoff_token: token, saas_workspace_uuid: ws, }), }) } catch (err) { return ( ) } let payload: { token?: string; user?: any; message?: string } = {} try { payload = await response.json() } catch { // ignore — handled below } if (!response.ok || !payload.token || !payload.user) { return ( ) } await applyHandoff(payload.token, payload.user, parsed.toString().replace(/\/$/, ""), ws) redirect("/") } function ActivationError({ title, detail }: { title: string; detail: string }) { return (

{title}

{detail}

Re-open the garage from the SaaS dashboard to get a fresh link.

) }