Skip to main content
The Node.js quickstart covers the calls themselves: create a user, send a notification, route it, start a journey. This page is the Next.js wiring around them. Where the Courier client lives in an App Router app, how to send from a Server Action, and how to add an in-app inbox that updates live, with the API key never leaving the server. It follows the Next.js quickstart repo, which you can clone and run in about five minutes. What you need
  • The Node.js quickstart done, or at least a Courier API key in COURIER_API_KEY and a user in Courier.
  • A Next.js App Router app on Node 20.9 or newer, with @trycourier/courier installed. Add @trycourier/courier-react for 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 in app/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.
Render <Inbox /> in a page, then send to that user with the inbox channel. The message appears without a refresh.

Next steps