# Restrict sign-up to your company's email domain

> Restrict sign-up to your company's email domain by setting allowed_email_domains with the CLI or API to block unauthorized user registrations.

**You can restrict sign-up to your company's email domain by running `vibiz auth domains acme.com` or passing `allowed_email_domains` to the sign-in settings API.** Once set, any attempt to register an account using an email address outside your list is blocked automatically. This check applies across all enabled sign-in methods, including email and password, magic links, and Google sign-in.

When building an internal workplace tool, a private company portal, or a tenant dashboard for specific client organizations, public registration is a liability. Restricting registrations at the sign-in service level ensures that accounts are created only by users who hold a corporate email address, without requiring you to write custom validation logic or database triggers.

## Why restrict sign-up to corporate email domains?

Opening user registration to the public is the standard pattern for consumer software, but internal tools and enterprise applications open only to invited users require strict access boundaries. Setting allowed email domains helps you solve three problems:

- **Accidental exposure:** If your app is accessible on the public internet, anyone finding the sign-in page could create an account and potentially consume database storage or backend resources.
- **Data segmentation:** Internal employee applications (such as administrative control panels or internal knowledge bases) must only admit users who belong to your team.
- **Provider matching:** When employees sign in using workplace accounts via Google, restricting registration to your domain guarantees that personal addresses are rejected even if the user is logged into multiple Google profiles in their browser.

By delegating domain enforcement to the [Sign-in](https://thelastapi.dev/docs/sign-in) service, the rule is applied before user rows are ever created in your project's database.

## How email domain restrictions work across authentication flows

When you configure an allowed domain list, the sign-in service checks the domain part of the email address (everything following the `@` symbol) during user registration.

The restrictions apply to all sign-in channels:

1. **Email and password:** If a user submits an email address with an unapproved domain during sign-up, registration fails immediately.
2. **Magic links:** Magic links requested for unauthorized email domains will not be generated or sent.
3. **Google and GitHub sign-in:** If an employee attempts to sign in via Google or GitHub, the callback extracts the verified email address. If the domain does not match your allowed list, the account creation step is refused.

If your project uses Google sign-in with our shared keys, you can onboard your entire team without configuring your own OAuth client IDs or consent screens. For step-by-step setup, see [how to add Google sign-in without your own OAuth app](https://thelastapi.dev/blog/add-google-sign-in).

| Configuration field | Value type | Limit | Effect |
| --- | --- | --- | --- |
| `allowed_email_domains` | Array of strings | Up to 50 domains | Only matching domains can register |
| `none` (or empty array) | Empty list | Default state | Public sign-up; any valid domain allowed |
| `disable_sign_up` | Boolean | `true` or `false` | Disables new registrations entirely |

## Setting allowed email domains with the CLI

The `vibiz` CLI allows you to configure domain restrictions directly from your terminal.

To set one or more allowed domains for your live production project, run the `vibiz auth domains` command with a comma-separated list:

```bash
vibiz auth domains acme.com,partner.com
```

If you are developing locally and want to test these restrictions against your local development environment, use the `--dev` flag:

```bash
vibiz auth domains acme.com --dev
```

To remove the restriction and reopen sign-up to any valid email address, pass `none`:

```bash
vibiz auth domains none
```

To inspect your current authentication configuration, run `vibiz auth`:

```bash
vibiz auth
```

For your local setup, run `vibiz auth --dev` to inspect active providers, localhost permissions, and your development allowed domain list.

## Updating allowed email domains over the HTTP API

If you configure authentication programmatically or through CI/CD pipelines, you can update settings using a `PATCH` request to the auth settings endpoint.

Here is how to update your development environment using `curl`:

```bash
curl -X PATCH "https://thelastapi.dev/v1/projects/prj_123/auth/settings?env=development" \
  -H "Authorization: Bearer $VIBIZ_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "allowed_email_domains": ["acme.com", "contractors.acme.com"]
  }'
```

To apply the same rule to production, omit the `?env=development` query parameter and send the request with a full-access API key:

```bash
curl -X PATCH "https://thelastapi.dev/v1/projects/prj_123/auth/settings" \
  -H "Authorization: Bearer $VIBIZ_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "allowed_email_domains": ["acme.com"]
  }'
```

The API accepts up to 50 domains in the `allowed_email_domains` array. Submitting an invalid format or an out-of-range count returns an `invalid_request` (HTTP 400) error.

## Managing development and production environments safely

Every project on thelastapi includes two distinct environments: production and development. Each environment maintains its own isolated sign-in service, user records, and database branch.

When managing settings, permissions depend on your key tier:

- **Full-access keys:** Held by account owners and human developers via the CLI or console. They can modify production authentication settings, rotate production secrets, and manage domain registrations.
- **Limited keys:** Intended for autonomous coding agents and automated build processes. Limited keys can modify development sign-in settings (`--dev`) but cannot alter production authentication settings.

If an automated agent with a Limited key attempts to update production authentication rules, the API returns:

```json
{
  "code": "forbidden",
  "status": 403,
  "details": {
    "reason": "owner_only",
    "permission": "auth.production:write",
    "grant_url": "https://thelastapi.dev/keys/key_123/allow?permission=auth.production:write"
  }
}
```

To let an agent or service make this specific change without granting full owner rights, the account owner can visit the provided `grant_url` and grant the `auth.production:write` permission. Learn more about scoped permissions in [Keys and environments](https://thelastapi.dev/docs/keys).

## Testing sign-in restrictions in your application

When using the `nextjs-saas` template (`vibiz init --template nextjs-saas`), authentication flows are pre-wired. The app server loads session state using `currentUser()` from `lib/auth/server.ts`, and client flows submit to `/api/auth/*`.

First, spin up your local development environment:

```bash
vibiz dev
```

This creates a dedicated development database branch with your tables and no production data, sets up development authentication, and writes your secrets to `.env.development.local`.

Next, restrict development sign-up to your test domain:

```bash
vibiz auth domains acme.com --dev
```

Now test the behavior inside your Next.js application. You can review how email and password flows handle verification in [email and password sign-in with verification codes](https://thelastapi.dev/blog/email-password-sign-in-verification), or review general application wiring in [how to add sign-in to a Next.js app](https://thelastapi.dev/blog/add-sign-in-nextjs-app).

```ts
import { vibiz } from '@vibiz/app';

// In your server route or component
export async function handleRegistration(formData: FormData) {
  const email = formData.get('email') as string;
  const password = formData.get('password') as string;

  try {
    const res = await fetch(`${process.env.VIBIZ_AUTH_BASE_URL}/sign-up`, {
      method: 'POST',
      headers: { 'Content-Type': 'application/json' },
      body: JSON.stringify({ email, password }),
    });

    if (!res.ok) {
      const error = await res.json();
      // Users registering with unauthorized domains receive an invalid_request error
      return { success: false, error: error.message };
    }

    return { success: true };
  } catch (err) {
    return { success: false, error: 'Registration failed' };
  }
}
```

If you host your frontend on external infrastructure rather than our hosting, you can still manage authentication seamlessly. Run `vibiz domains add app.example.com --elsewhere` so the authentication service recognizes your production origin. Details are covered in [Domains](https://thelastapi.dev/docs/domains).

## Combining domain restrictions with other auth controls

Domain whitelisting works alongside several other authentication controls available in your auth settings:

- **Disabling sign-up entirely:** Setting `email_password.disable_sign_up: true` blocks all new public registrations, even from approved domains. Existing users can still log in.
- **Requiring email verification:** When using email and password, setting `email_password.require_email_verification: true` ensures users prove ownership of their workplace address with a one-time code (`otp`) before their account is activated.
- **Magic link expiry:** You can enforce short-lived magic links by tuning `magic_link.expires_in_minutes` between 5 and 1440 minutes.

If an employee leaves your organization and loses access to their corporate inbox, they will no longer be able to receive magic links or complete one-time password verifications.

To secure your company's sign-up flow today, configure your domain list with `vibiz auth domains yourcompany.com` or create your account at [thelastapi.dev/start](https://thelastapi.dev/start) to start building.

## Frequently asked questions

### Can I allow multiple company email domains at the same time?

Yes. You can list up to 50 allowed email domains by separating them with commas in the CLI command (`vibiz auth domains domaina.com,domainb.com`) or by passing an array of domain strings to the `allowed_email_domains` field in the API.

### What happens if an employee tries to sign up with a personal Gmail address via Google sign-in?

The authentication service inspects the email address returned by Google during OAuth. If the address does not match one of your configured domains in `allowed_email_domains`, sign-up is blocked and no user account is created.

### Does restricting email domains affect existing users who already created accounts?

No. Domain restrictions apply during the registration and sign-up phase. Existing accounts created before the restriction was applied can still log in unless sign-in is disabled or the user is deleted.

### Can an automated AI agent change our production domain restrictions?

By default, no. Automated agents using Limited keys receive a `403 forbidden` error with reason `owner_only` if they attempt to change production authentication settings. The account owner must either apply the change or explicitly grant the agent the `auth.production:write` permission.

---

Published 2026-11-15 · https://thelastapi.dev/blog/restrict-sign-up-email-domain
