- The Node.js quickstart done, or at least a Courier API key in
COURIER_API_KEYand a user in Courier. - A Next.js App Router app on Node 20.9 or newer, with
@trycourier/courierinstalled. Add@trycourier/courier-reactfor the inbox.
1. Send from a Server Action
@trycourier/courier is a server SDK and your API key is a server secret, so every Courier call belongs in a Server Action, a Route Handler, or a server component. new Courier() reads COURIER_API_KEY from the environment. The template lives in Design Studio, so the copy and the channel routing change without a deploy.
2. Mint an inbox token in a Route Handler
The in-app inbox runs in the browser, so it needs a token that is safe to send there: a JWT scoped to one user and expiring, signed by your API key on the server. The repo does this inapp/api/courier/token/route.ts, and reads the user id from the session rather than from the request, because a caller who can name any user can read that userβs inbox.
3. Render the inbox as a client component
<CourierInbox /> uses hooks and renders as a custom element, so it needs "use client". It does not need next/dynamic with ssr: false. Sign in inside an effect, and guard it, because React runs effects twice in development and a second sign-in would sign the first user out.
<Inbox /> in a page, then send to that user with the inbox channel. The message appears without a refresh.
Next steps
- Next.js quickstart repo: clone it, add a key, run
npm run devandnpm run send. - Node.js quickstart: users, routing, journeys, delivery status.
- In-app inbox: scopes, tenants, and the rest of the inbox.
- Node.js SDK reference.
- React SDK reference.