ContentsReact and server

Get started

React and server

The form as a React component in your app, and on your server the check whether someone is invited.

Install

npm install nearlyin

The package has three entry points: nearlyin for the form, nearlyin/server for your server and nearlyin/webhooks for checking webhooks. You need React 18 or newer only for the form.

The form

The component brings its own styles and loads nothing from other servers. Allow the address of your page in the dashboard under “Allowed origins”.

signup.tsx

import { WaitlistForm } from "nearlyin";

export function Signup() {
  return (
    <WaitlistForm
      productKey="ni_pk_test_…" // ni_pk_live_… when you go live
      serviceUrl="https://nearlyin.com"
      locale="de"
    />
  );
}

More props: texts and colors for texts and colours of your own, referral and source if your page knows the referral code and the source itself, onSuccess for a next step of your own.

Let invited people in

Set two variables on your server. The secret key must never reach the browser.

.env

NEARLYIN_URL="https://nearlyin.com"
NEARLYIN_SECRET_KEY="ni_sk_test_…"

register.ts

import { isInvited, redeemInvite, verifyInvite } from "nearlyin/server";

// The invitation mail links to your product with ?invite=<code>.

// When the page opens: who is this? Does not use the code up.
const email = await verifyInvite(searchParams.invite); // "ada@example.com" or null

// When you create the account: works exactly once.
const invited = await redeemInvite(code);
if (!invited) throw new Error("This invitation is no longer valid.");

// Without a code: is this address allowed in?
if (!(await isInvited(email))) throw new Error("Not invited yet.");

For Clerk, Auth.js, Supabase Auth and Better Auth there is a complete example each.

Without the package

Every function of the package is one call to the API. If your server does not run JavaScript, redeeming a code looks like this:

// The same without the package: one POST with the secret key.
const response = await fetch(`${process.env.NEARLYIN_URL}/api/v1/invites/redeem`, {
  method: "POST",
  headers: {
    Authorization: `Bearer ${process.env.NEARLYIN_SECRET_KEY}`,
    "Content-Type": "application/json",
  },
  body: JSON.stringify({ token: code }),
});
const { valid, email } = await response.json();