---
title: "Hand out invite codes and access links"
description: "While your app is in early access or invite only, administrators admit people from the console's Access tab: invite codes to share, access links for a whole cohort, invitations by address with no email unless asked, and useInvite to redeem them."
canonical_url: "https://nuxt-backend.dev/docs/build/growth/launch/invites"
---
# Hand out invite codes and access links

> While your app is in early access or invite only, administrators admit people from the console's Access tab: invite codes to share, access links for a whole cohort, invitations by address with no email unless asked, and useInvite to redeem them.

Version: nuxt-backend 0.6.x · Tab: Build · Kind: how-to · Status: stable

Every page: [llms.txt](https://nuxt-backend.dev/llms.txt) · Skill for coding agents: [nuxt-backend](https://nuxt-backend.dev/.well-known/skills/nuxt-backend/SKILL.md)

Commands use npm; use your project's package manager.

- [Source](https://github.com/qruto/nuxt-backend/blob/main/src/convex/integrations/launch.ts)

While your app is closed, a new address needs a ticket to sign up ([Launch in phases](https://nuxt-backend.dev/docs/build/growth/launch)). Administrators hand tickets out in the admin console's **Access** tab, three ways: an invite code to share, an access link for a cohort, or an invitation by address. The tab also shows the current phase and moves it on.

- **Natively:** neither Better Auth nor the email provider has invite codes. Better Auth's workspace invitations admit one address into one workspace, not into the app (checked on 2026-10-25).
- **The package adds:** invite codes and access links as hashed tokens in the `backend` component, checked inside Better Auth's sign-up hooks, a redemption ledger per label, and invitations by address that send no email unless you ask.

## Invite codes

An invite code is short enough to read out or type: `7KQ2M-XW9PA`. A person types it on the sign-in page's `invite-code` step, after their sign-in code.

Administrators create codes in the Access tab, each with:

- **a label**, such as `friends-of-the-team`, which names its cohort in the trail and in [growth funnels](https://nuxt-backend.dev/docs/build/growth/measure);
- **a number of uses**: 1 for a personal code, more for one you post in a community;
- **an expiry**, optional.

The tab shows each code once, when it is made. The database keeps only a hash, so neither a backup nor a log can give the code out again. Codes are read without case and without the dash, and look-alike characters count as one: `O` reads as `0`, `I` and `L` as `1`.

From your own code, `access.invites.create` makes one and returns it, once, like the tab:

```ts [backend/invites.ts]
import { v } from 'convex/values'
import { admin } from './functions'
import { access } from './access'

// One code for an illustrators' meetup: 30 uses, valid for two weeks.
export const createMeetupCode = admin.mutation({
  args: { label: v.string() },
  handler: (ctx, { label }) =>
    access.invites.create(ctx, { label, maxUses: 30, expiresAt: Date.now() + 14 * 24 * 60 * 60 * 1000 }),
})
```

## Access links

An access link admits a cohort without anyone typing a code: everyone who signs up through the link from one launch post. Administrators create links in the Access tab, each with a label, a number of uses and an expiry, all three required. Revoking a link closes it at once.

The link opens `/invite`, a page the module mounts, with the token in the fragment: `https://panels.example/invite#<token>`. Browsers never send a fragment to a server, so the token stays out of your host's logs. The page:

1. strips the token from the address as it opens, before it knows who is signed in, and keeps it for the tab, so a reload still has it;
2. checks it through a rate-limited call, so an expired or used-up link says so before anyone signs in, and keeps a valid one for the tab;
3. sends the person to the sign-in page, which hands the token over with the code check.

Without a link, or after one that admits nobody, the page takes a code typed by hand, a code a friend read out, and points to the waitlist in early access. A visitor who is signed in already has nothing to redeem: the page checks nothing and keeps nothing, and the link they opened still admits a friend.

The account's creation checks the token again and counts the use. Logs and events name the link by its label, never its token.

## Show it in a page

`useInvite()` redeems a code or a link on a page of your own:

```vue [app/pages/join.vue]
<script setup lang="ts">
const { check, status, isPending, error } = useInvite()
const code = ref('')
</script>

<template>
  <form @submit.prevent="check(code)">
    <label for="invite-code">Invite code</label>
    <input id="invite-code" v-model="code" autocomplete="off" spellcheck="false" placeholder="7KQ2M-XW9PA">
    <button type="submit" :aria-disabled="isPending || undefined">Check my code</button>
  </form>
  <NuxtLink v-if="status === 'valid'" to="/login">Continue to sign in</NuxtLink>
  <p v-else-if="error" role="alert">{{ error.message }}</p>
</template>
```

A page of your own at `/invite`, the page an access link opens, passes `useInvite({ fromAddress: true })`, as the packaged page does: once it mounts, the link's token leaves the address at once and the tab keeps it, and once the session settles a signed-in visitor's is forgotten and anyone else's is checked. `linkChecked` turns `true` when that is done (the server renders a wait until then), and `asked` says whether there was a ticket to check at all.

`check(codeOrToken)` checks it and keeps a valid one for the tab, so the next code check carries it. `status` is `valid`, `expired`, `used-up`, `revoked` or `unknown`. With no argument, `check()` reads an access link's fragment from the address. It also returns `isKept` and `forget()`.

`checkInvite` is a mutation, so its rate limit can count: `inviteCheck` per signed-in caller, `inviteCheckGlobal` across the deployment.

## Invite people by address

"Invite by address" takes a pasted list or a CSV, up to 500 addresses at a time, and an optional label such as `beta-1`. Each address gets a ticket that expires after 30 days unused.

- **No email unless you ask.** Sending an invitation to people who didn't ask for one is direct marketing in most places. So the tab adds the tickets silently by default, and you announce through a broadcast to people who opted in ([Guardrails on growth features](https://nuxt-backend.dev/docs/start/concepts/principles#guardrails-on-growth-features)).
- **"Email them"** sends each person a plain "You're invited" email in the layout, with who you are, a link to your privacy policy (`backend.pages.privacy`) and the sign-in link (`backend.pages.login`), both from `paths`; the sign-in link holds no token and no address. It carries the one-click unsubscribe such an email needs, follows the weekly cap and quiet hours, and goes at about a hundred an hour, one wave after another, so a wave never crowds out sign-in codes. The emails go from an action of their own, by the invitations' ids. It needs the email instance and the action re-exported:```ts [backend/access.ts]
export const access = setupAccess(components, { audit, email, paths })
export const { emailInvitations } = access.api
```

<br />

The words are the `email.accessInvitation` labels. An invitation used, expired or revoked before its email goes gets none, and an email that cannot go leaves the invitation standing (`access.invitation_unsent`).
- **Cleaned first.** Existing accounts, suppressed addresses and reserved domains (`example.com`, `.test`, `.invalid`, `localhost`) are skipped.
- **Revoke** deletes an unused ticket. A used one is an account: ban it like any other ([Run the admin console](https://nuxt-backend.dev/docs/build/auth/admin#what-an-administrator-may-do)).

From your own code, `access.admit(ctx, { emails, label })` adds the same tickets, with no email. `useAccessAdmin().admit(emails, label, { email: true })` is the tab's "Email them". From the terminal, for a drill or an end-to-end test, [`npx nuxt-backend access admit <email>`](https://nuxt-backend.dev/docs/reference/cli#access-admit) adds them too, with no email and nobody signed in to the console.

## Let members bring friends

Member tickets let every member bring a few friends past the waitlist while the app is closed. Each member holds one access link, minted the first time they ask for it and read back after, to share however they like:

```ts [backend/access.ts]
import { DAY } from 'nuxt-backend/rate-limit'

export const memberTickets = access.memberTickets({ uses: 3, lifetime: 60 * DAY })
export const { getMemberTicket, issueMemberTicket } = memberTickets.api
```

`useMemberTicket()` reads and mints it on a page of your own:

```vue [app/components/BringFriends.vue]
<script setup lang="ts">
const { ticket, link, issue, isPending } = useMemberTicket()
</script>

<template>
  <button v-if="ticket?.state === 'none'" type="button" :aria-disabled="isPending || undefined" @click="issue()">
    Get a link for {{ ticket.uses }} friends
  </button>
  <p v-else-if="ticket?.state === 'issued'">
    {{ ticket.left }} of {{ ticket.uses }} left until {{ new Date(ticket.expiresAt).toLocaleDateString() }}: {{ link }}
  </p>
</template>
```

- **One link per member.** `issue()` mints it on the first ask and answers the same link after, until it expires, used up or not. Once it expires, the next ask mints a fresh one with its uses back. `ticket.state` is `none` before the first ask, `issued` after, `open` once the app is public and `off` while the program is. Each mint is recorded as `access.invite_created`, with the member as the actor and the label `member`.
- **An access link like any other.** `link` opens `/invite#<token>` (`backend.pages.invite`) on the page's own origin, so the token stays out of every server's logs, and the account's creation counts the use. A sign-up through it is the `member-ticket` ticket: the ledger labels it `member:<userId>`, and the Users tab shows it as "A member's ticket". The activity trail and the [growth funnels](https://nuxt-backend.dev/docs/build/growth/measure) count these sign-ups as one cohort, `member`, without the member's id.
- **Nothing secret is kept.** The token is derived from the member and the ticket's expiry under `AUTH_SECRET`, so the member reads it back while the database keeps only its hash, as for any link. A rotation of the secret keeps the link working. Once the previous secret retires, the member reads `none` with the uses their ticket has left, and the next ask gives the same ticket a new link, with its uses left and its end: the old link stops, and no second ticket is minted beside it.
- **No chains, unless you ask.** An account a member ticket admitted holds none of its own (`off`), as with workspace invitations: one member brings their friends, not a chain of strangers past the waitlist. `memberTickets({ chain: true })` lets every member hold one.
- **The friend counts as a referral, if you ask.** `memberTickets({ referrals })`, with your app's [referral program](https://nuxt-backend.dev/docs/build/growth/offers/referrals) imported from `backend/referrals.ts`, claims each friend a member's ticket admits as that member's referral while the friend's account is made (`referrals.claimFor`). The ticket decides, never the address: the link carries no code, so a link someone reposts with a `?ref=` of their own, or a friend who signs in on another page or in another browser, still counts for the member who let them in. The referral program's own checks hold: the first referral claimed wins, an address that is the member's own claims nothing, and the member's reward waits for the friend's first paid order and the hold. A claim that cannot be made never fails the sign-up (`access.referral_unclaimed`). Without `referrals`, a member's ticket claims nothing.
- **Your own switch.** `enabled(ctx)` turns the program off without a deploy, from a [flag](https://nuxt-backend.dev/docs/ship/operate/flags) say: `enabled: ctx => flags.isEnabled(ctx, 'memberTickets')`. While it is off, nobody reads or mints a ticket, and the links already shared admit nobody: a check or a sign-up reads them as `revoked` until it is on again. Each sign-up through a member's link is checked against its member and the switch in the transaction that takes the use.
- **Each member's own.** Nobody signed out reads one, and an administrator visiting the member neither reads nor mints theirs (`forbidden`, reason `impersonating`). A banned member reads none and mints none (`forbidden`, reason `banned`), and their link admits nobody (`revoked`) until the ban lifts. An account's erasure deletes its tickets, so a link it shared stops working, and the friends they admitted keep their ticket with the label `member`.
- **In the Access tab.** The member tickets that end last list under the codes and links, by member, with their uses, end and status, never the token. Revoke stops one at once, and its member reads `off` until it would have ended: revoking is no fresh start. The backend's maintenance removes a member ticket 30 days after it ended; until then, its old link reads `expired`.

## Who invited whom

Each ticket remembers how it was given: a code and its label, a link, a member's ticket, an address an administrator invited, or a workspace invitation. The Users tab shows it on each account ("Signed up with"), the activity trail records it as `access.ticket_used`, and the [growth funnels](https://nuxt-backend.dev/docs/build/growth/measure) count sign-ups per label.

## What happens when…

- **A code is unknown, expired, used up or revoked:** `useInvite().check` reads it as that `status`, and the `invite-code` step asks again. Neither is an error.
- **Someone guesses codes:** the check is rate-limited per signed-in caller and across the deployment, and the code check that carries a code per address, then refused as [`rate_limited`](https://nuxt-backend.dev/docs/reference/backend/errors#rate_limited). A code has 50 bits, so guessing one is out of reach anyway.
- **The last use of a code is taken in the same moment by two people:** the account creations run in one transaction each, so one gets it and the other meets the `invite-code` step.
- **An administrator changes a code while visiting another account:** the write is refused as [`forbidden`](https://nuxt-backend.dev/docs/reference/backend/errors#forbidden) with reason `impersonating`.
- **A pasted list holds a malformed address:** that row is skipped and reported, and the rest are admitted.

## Limits

- **500 addresses per paste.**
- **A code shows once.** Lost codes are revoked and made again: the hash can't be read back.
- **No user-made codes.** Only administrators and your server code create invite codes. A member shares their [member ticket](#let-members-bring-friends), a link; for rewards beyond the waitlist, use [referrals](https://nuxt-backend.dev/docs/build/growth/offers/referrals).

## Test it

A code an administrator makes checks as valid until its uses run out:

```ts [backend/invites.test.ts]
import { asUser, defineBackendTestApp } from 'nuxt-backend/test'
import { expect, test } from 'vitest'
import { api } from './_generated/api'
import schema from './schema'

const testApp = defineBackendTestApp(schema, import.meta.glob('./**/*.ts'))

test('a new meetup code checks as valid', async () => {
  const t = testApp()
  const admin = await asUser(t, { role: 'admin' })
  const code = await admin.mutation(api.invites.createMeetupCode, { label: 'meetup' })
  expect(await t.mutation(api.access.checkInvite, { code })).toMatchObject({ status: 'valid' })
})
```

## Related

- [Launch in phases](https://nuxt-backend.dev/docs/build/growth/launch): the phases and every kind of ticket.
- [Run a waitlist](https://nuxt-backend.dev/docs/build/growth/launch/waitlist): admitting from the waitlist in waves.
- [Measure growth](https://nuxt-backend.dev/docs/build/growth/measure): what each code, link and label brought.
- [Get email into inboxes](https://nuxt-backend.dev/docs/build/email/delivery/deliverability): why invitation emails go out slowly.
- [Resend](https://nuxt-backend.dev/docs/services/resend): the provider that sends invitation emails.


## Sitemap

See the full [sitemap](https://nuxt-backend.dev/sitemap.md) for all pages.
