---
name: waitlistly-setup
description: Connect a web app to Waitlistly, the waitlist backend. Wires three API calls (collect signups, gate sign-up with an invite code, report activations) into the user's existing form and auth. Use when asked to "set up Waitlistly", add a waitlist backend, or make an app invite-only with Waitlistly.
---

# Set up Waitlistly in this app

You are connecting this codebase to Waitlistly. Waitlistly collects waitlist signups through an API, releases access in cohorts with single-use invite codes, and measures how many signups become users. It has no UI to embed: the user keeps their own page, form and auth.

Work through the steps in order. Keep changes small and in the app's existing style. Ask the user only when a step says to.

## 1. Detect the stack

Find and note:

- **Framework**: Next.js (App or Pages Router), React + Vite, SvelteKit, Nuxt/Vue, Astro, Remix/React Router, or a plain backend (Express, Hono, Fastify, Django, Rails, Laravel…).
- **Auth library**: Supabase Auth, Firebase Auth, Clerk, Auth.js/NextAuth, Better Auth, Lucia, or custom.
- **Env file**: `.env.local`, `.env`, or the framework's equivalent, and the prefix that exposes a variable to the browser (`NEXT_PUBLIC_`, `VITE_`, `PUBLIC_`, `NUXT_PUBLIC_`).
- **The waitlist form**: a form or component that collects an email for early access. If there is none, ask the user where it should go, then add a minimal one (email input and button) that matches the page's existing styles.
- **The sign-up flow**: the place where a new account is created.

If the app uses **Clerk**, tell the user Clerk has its own waitlist mode, and ask whether they still want Waitlistly before continuing.

## 2. Add the keys

Add these to the env file, with the browser prefix on the public key only:

```bash
<BROWSER_PREFIX>WAITLISTLY_PUBLIC_KEY=pk_...   # safe in browser code
WAITLISTLY_SECRET_KEY=sk_...                    # server only. Never import it into client code
```

If the user didn't give you the keys, leave placeholders and tell them: "Copy your keys from Waitlistly → Developers → API keys." Add both names to `.env.example` if the project has one. Never print or commit a real secret key.

## 3. Collect: add a contact when the waitlist form is submitted

Call this from the browser (or a server action) on submit:

```
POST https://waitlistly.live/api/v1/contacts
Headers: Content-Type: application/json
         X-Waitlistly-Key: <public key>
Body:    { "email": string (required), "name"?: string, "ref"?: string, "answer"?: string,
           "fields"?: { [key]: string|number|boolean }, "website"?: "" }
```

- Read `ref` from the page URL (`?ref=`) and send it, so referrals count.
- Send any extra form inputs (company, role, phone…) in `fields`, keyed by the API keys listed in the console under **Settings → Contact fields**. Values are checked against each field's type (email, phone with country code like `+14155550182`, URL, number, select, yes/no, date as `YYYY-MM-DD`). A value that doesn't fit is dropped and listed in `warnings`; the signup is still saved.
- Add a visually hidden text input named `website` and send its value. Leave it empty; it traps bots.
- Disable the button while the request is in flight.

Handle the response:

| Response | Show |
| --- | --- |
| `200` with `status: "joined"` | "You're #{position} in line" and `referral_link` with a Copy button: "Share this link to move up." |
| `200` with `status: "pending_confirmation"` | "Check your inbox to confirm your spot." |
| `200` with `status: "already_joined"` | "You're already on the list." |
| `400` | The `error` message from the response, under the email field |
| `422` with `code: "invalid_field"` | A required field is missing or invalid. Show `error` next to the input named by `field`. |
| `429` | "Too many tries. Please wait a minute." |

Shortcut for plain sites: load `<script src="https://waitlistly.live/w.js" data-key="<public key>" async></script>` and call `Waitlistly.join({ email })`. It returns the same response and also captures `?ref=` and UTM tags.

## 4. Gate: only invited people can create an account

Invited people arrive at the sign-up page with `?invite_code=XXXX-XXXX`. Their email is not in the URL; look it up so they only choose a password.

- **Prefill the email** (browser, public key):

```
POST https://waitlistly.live/api/v1/invites/lookup
Headers: Content-Type: application/json
         X-Waitlistly-Key: <WAITLISTLY_PUBLIC_KEY>
Body:    { "code": "<invite code>" }
→ { "valid": true, "status": "sent", "email": "ada@example.com", "expires_at": "..." }
→ { "valid": false, "status": "expired" | "activated" | "revoked" | "not_found" }
```

  Or, if the page loads `w.js`, add `data-waitlistly-invite` to the sign-up `<form>`: it fills `[name=email]` and `[name=invite_code]` and fires `waitlistly:invite`. In React, call `await Waitlistly.invite()` and set state from `email`.
- If `valid` is `false`, show "This invite is not valid or has expired" and link to the waitlist instead of the sign-up form.
- Carry the code through the sign-up form (hidden input, state, or cookie).
- On the **server**, before creating the account:

```
POST https://waitlistly.live/api/v1/invites/verify
Headers: Content-Type: application/json
         Authorization: Bearer <WAITLISTLY_SECRET_KEY>
Body:    { "code": "<invite code>" }
→ { "valid": boolean, "status": string, "email": string, "expires_at": string }
```

- If `valid` is `false`, stop and show "This invite is not valid or has expired."
- If `email` doesn't match the email being registered (case-insensitive), stop and show "This invite was sent to a different email."
- Put this check where the account is actually created, in a server action, API route, auth hook or callable function, never only in the browser.

Ask the user whether sign-up should be **invite-only** (no code means no account) or **open with priority** (codes are optional and only reported). Default to invite-only.

## 5. Activate: report the new user

Right after the account is created successfully, on the server:

```
POST https://waitlistly.live/api/v1/activations
Headers: Content-Type: application/json
         Authorization: Bearer <WAITLISTLY_SECRET_KEY>
Body:    { "code": "<invite code>" }   (or { "email": "<email>" })
→ { "status": "activated", "already": boolean }
```

Don't fail the sign-up if this call fails. Log it and continue.

## 6. Verify

1. Run the project's type-check and lint.
2. If the dev server can run, submit the waitlist form with `test-<random>@example.com` and confirm a `200` with `status: "joined"`. Addresses at `example.com` are never emailed.
3. Tell the user to open **Waitlistly → Developers → Integration** to see each step marked as received, and **Request log** for every call.

## 7. Report back

Summarize briefly:

- the files you changed
- the env variables they still need to fill in
- whether sign-up is invite-only
- one line on what to do next: "In Waitlistly, open Settings → Access rules and set your sign-up URL, then release a first cohort from Access → Cohorts."

## Rules

- The secret key never reaches the browser: no browser env prefix, no client imports, no logging.
- Don't restyle the existing page or replace the user's form. Wire into what exists.
- Don't add new dependencies; `fetch` is enough.
- Docs: https://waitlistly.live/docs. API reference: https://waitlistly.live/docs/reference/rest-api
