# Private & invite-only apps

> Control who can open your app and register — from public launches and invite-only betas to member portals and internal team tools.

- Canonical: https://exaspark.ai/docs/app-visibility-and-invites/

## Four visibility models for Live apps

Not every published app should let anyone on the internet click **Sign up** and enter. Pick one clear visibility model upfront so navigation, tables, and server auth checks stay aligned from day one.

| Visibility model | Public pages | Who can register | Best fit |
| --- | --- | --- | --- |
| **Public app** | Anyone on the web | Open sign-up or social login | Storefronts, bookings, SaaS apps, public directories |
| **Invite-only beta / waitlist** | Marketing page and waitlist form only | Valid invite token or admin-approved email | Controlled betas, founder communities, cohorts |
| **Member-only client portal** | Branded sign-in screen (`/login`) only | Invited clients or paid subscribers | Agency portals, coaching hubs, B2B dashboards |
| **Internal company tool** | Branded sign-in screen (`/login`) only | Verified `@company.com` teammates plus invite | Ops dashboards, inventory, finance approvals |

## Why server-gated access beats hiding routes in the UI

Putting a login modal over a dashboard while `/api/clients` still returns data leaks every record in Chrome DevTools. True private visibility enforces two layers together:

- **Server-enforced route and API gates.** Every non-public endpoint verifies an active session and approval status (`active`, workspace membership, or invite) before querying the database, returning `401 Unauthorized` when signed out and `403 Forbidden` when unapproved.
- **Search-engine exclusion (`noindex`).** Emit `<meta name="robots" content="noindex, nofollow">` on private routes and omit internal URLs from `sitemap.xml` so search engines never index private screens.

## Designing clean invite tokens and waitlists

Whether you are admitting 25 beta testers a week or onboarding paying agency clients, treat invite links like one-time keys — never reusable plain URLs like `/signup?invited=true`.

Here is a battle-tested schema blueprint for waitlists and expiring single-use invites:

```text
waitlist_requests
  id                  PK (uuid)
  email               text, unique (lowercase), not null
  full_name           text, not null
  company             text, nullable
  status              enum('pending', 'approved', 'declined'), default 'pending'
  created_at          timestamp (UTC)

invites
  id                  PK (uuid)
  email               text (lowercase), not null
  role                enum('member', 'staff', 'admin'), default 'member'
  workspace_id        FK -> workspaces.id, nullable
  token_hash          text, unique, not null     -- store hash only, never raw token
  invited_by_user_id  FK -> users.id, not null
  expires_at          timestamp (UTC), not null  -- e.g. 7 days from creation
  accepted_at         timestamp (UTC), nullable
  revoked_at          timestamp (UTC), nullable
  created_at          timestamp (UTC)
```

Five small rules make this invite flow rock-solid in production:

- **Hash the invite token at rest.** Generate a high-entropy random token on the server, email the raw token once inside `/accept-invite?token=...`, and store only its cryptographic hash in `invites.token_hash`.
- **Bind invites to the invited email.** When the recipient opens the link, pre-fill and lock their invited email address (or verify that their Google/Apple login matches `invites.email`) so forwarded links cannot be claimed by strangers.
- **Expire and consume atomically.** Set `expires_at` to 7 days by default, reject expired or revoked invites cleanly, and mark `accepted_at` inside a database transaction so the same link can never create two accounts.
- **Give admins full visibility.** Build an **Invites** tab showing **Pending**, **Accepted**, **Expired**, and **Revoked** rows with one-click **Resend** (rotates token and extends expiry) and **Revoke** actions.
- **Keep open registration disabled on the server.** Removing the **Sign up** link from your header is not enough — your `POST /api/auth/register` route itself must reject registrations that lack a valid, unconsumed invite token.

## Domain allowlists and internal tool guardrails

For internal company apps, founders often ask to "allow anyone with an `@acme.com` email." That is convenient, but only safe when paired with strict email verification.

- **Never trust an unverified email/password signup.** If someone registers `fake@acme.com` with a password and your app skips email verification, an outsider walks straight into your internal dashboard.
- **Prefer Google Workspace or Microsoft SSO for internal tools.** Corporate SSO confirms the teammate actually owns an active company mailbox — and if they leave the company and IT suspends their mailbox, they can no longer sign back in.
- **Combine domain allowlist with explicit role approval for sensitive tools.** For finance, payroll, or admin portals, require both a verified `@acme.com` address and an explicit admin invite so a contractor or intern does not inherit automatic access.

## Step-by-step: launching an invite-only beta or private portal

Follow these five steps to lock down your app cleanly before sharing your Live URL.

1. **Lock registration on the server first** — Configure your app so only `/login`, `/accept-invite`, and (if using a beta waitlist) `/` plus `/waitlist` are public; every other page and API route requires an authenticated, active account.
2. **Add the invite manager and branded invite emails** — Wire the `invites` table to send crisp invite links using your configured sending domain so invites land in inboxes rather than spam. See [Branded email & delivery](https://exaspark.ai/docs/branded-email/).
3. **Bootstrap your first Live admin safely** — Remember that Preview accounts do not copy to Live. Allow your single owner email (or create your first Live account in **Cloud → Live** and promote it to `admin`) before disabling open sign-up so you never lock yourself out.
4. **Verify private gates in an incognito window** — Open your Live URL while signed out and test direct navigation to `/dashboard`, `/settings`, and your main `/api/...` routes to confirm every private route redirects or returns `401`.
5. **Test the full invite lifecycle end to end** — Send a real invite to a secondary email, confirm accepting works once, verify reloading the consumed link fails cleanly, and test clicking **Revoke** on a pending invite.

> **Example prompt (App):** Convert this app into an invite-only client portal. Keep only `/`, `/waitlist`, `/login`, and `/accept-invite` accessible to signed-out visitors, add `noindex, nofollow` metadata on all portal routes, and reject direct `POST /api/auth/register` attempts unless backed by a valid, unexpired, unrevoked single-use invite token hashed in an `invites` table. Add an Admin-only `/admin/invites` screen where admins can approve waitlist requests, invite clients by email with a chosen role (`member` or `staff`), send a 7-day expiring invite email, and resend or revoke pending invites. Ensure every private page and API route enforces session authentication server-side and returns `401` when signed out.

## Common visibility & invite pitfalls

If an invite flow stalls or a private portal behaves unexpectedly after Publish, check these five common causes.

| Issue | What went wrong | Clean fix |
| --- | --- | --- |
| **Founder locked out on Live after turning off open registration** | Preview admin account does not exist in Live, and Live blocks new sign-ups | Configure an explicit founder allowlist email for first login, or create and promote your Live admin in **Cloud → Live** |
| **Private API still returns JSON when signed out** | Login check was added only to frontend router instead of server API handlers | Add server auth middleware to every non-public `/api/*` endpoint returning `401` |
| **Invited client clicked "Continue with Google" using a personal Gmail instead of work email** | Invite was bound to `alex@company.com`, but user authenticated with `alex.personal@gmail.com` | Show a clear message naming the invited email ("This invite is for `alex@company.com` — sign in with that address or ask your admin to re-invite") |
| **Invite emails land in Promotions or Spam** | Sending domain lacked verified SPF, DKIM, and DMARC records | Connect your custom domain and authenticate DNS; see [Email authentication (SPF/DKIM/DMARC)](https://exaspark.ai/docs/email-authentication-dns/) |
| **Private portal login or client names appear in Google Search** | Missing `noindex` tags or client profile slugs leaked into `sitemap.xml` | Exclude all private routes from `sitemap.xml`, emit `noindex, nofollow`, and keep client data strictly behind auth |

> **Note:** **Workspace seats vs app members.** ExaSpark's **Pro** plan includes **3 builder seats** for teammates collaborating inside your ExaSpark studio workspace — that is separate from the customers, clients, or internal staff who sign into your **published app** via invites. See [Team & workspace roles](https://exaspark.ai/docs/team/).

## Next steps

- [Row-level data privacy](https://exaspark.ai/docs/row-level-data-privacy/) — Isolate each invited client's rows from every other client on the server.
- [Branded email & delivery](https://exaspark.ai/docs/branded-email/) — Send high-deliverability beta and client invites from your own domain.
- [Team & workspace roles](https://exaspark.ai/docs/team/) — Invite collaborators to build inside your ExaSpark studio workspace.

## From the blog

- [How to build a membership website](https://exaspark.ai/blog/how-to-build-a-membership-website/) — Architecting gated content, member sign-in, and recurring access cleanly.
- [User roles and permissions](https://exaspark.ai/blog/user-roles-and-permissions/) — Structuring public, invited member, staff, and admin access tiers.
- [How to get your first users](https://exaspark.ai/blog/how-to-get-your-first-users/) — Turning waitlists and invite-only betas into engaged early customers.
