Separate development and production sign-in
Separate development and production sign-in by isolating user tables, session cookies, and allowed origins across distinct environments.
On this page 8 sections
- Why development and production sign-in must stay separate
- How the two environments are isolated
- Configuring local sign-in with vibiz dev
- Handling authentication in application code
- Configuring social providers and settings per environment
- Managing production domains and allowed origins
- Protecting production credentials with Limited keys
- FAQ
To separate development and production sign-in, use isolated authentication instances where test credentials, redirect origins, and user directories never touch live production data. In thelastapi, adding sign-in provisions two distinct environments: a production instance bound to your verified live domains, and a development instance locked to http://localhost:3000 with its own user table stored in a dedicated database branch. Running vibiz dev generates local keys and configuration files automatically, ensuring team members and AI coding agents can test login workflows without accessing customer accounts.
When authentication is shared or improperly separated between staging and production, test users pollute customer databases, OAuth redirects expose local endpoints, and session cookies can leak across environments. Setting up strict environment boundaries prevents these issues from reaching production.
Why development and production sign-in must stay separate
Sharing an authentication provider or user store across development and production introduces three critical risks to an application:
- User directory contamination. If developers or automated tests sign up with mock addresses such as
test@example.com, those accounts clutter production tables. More dangerously, running migrations or test teardowns against a shared database can delete real customer accounts. - Redirect and origin hijacking. OAuth providers like Google and GitHub require registered redirect and callback URLs. Whitelisting
http://localhost:3000on a production OAuth client creates an attack vector where authorization codes can be diverted to an unauthenticated local port. - Session leakage. If session cookies share domains, secrets, or token-signing keys, a cookie issued by a local development server might be accepted by production endpoints, or vice versa.
A clean separation requires independent database records, environment-specific signing secrets, and distinct callback URLs.
How the two environments are isolated
When you add the auth resource to a project (vibiz add auth), it provisions sign-in alongside a serverless Postgres database. The production copy handles real traffic, while the development copy operates as an independent sandbox.
| Feature | Production environment | Development environment |
|---|---|---|
| User directory | Real registered customers | Isolated branch with identical schema and no rows |
| Allowed origins | Verified domains (allow_localhost: false) | Local testing origin (http://localhost:3000) |
| App key | Production vz_app_… key | Development vz_app_… key |
| Settings access | Owners and Full-access keys only | Full-access keys, Limited keys, and AI agents |
| Reset capability | Manual account management | Instant branch wipe via vibiz dev --reset |
Because the development sign-in service writes directly to a branched copy of your database, you can run registration tests, verify email formatting, and test user onboarding flows without touching live rows. For details on branch behaviour, read how to seed data in a development branch, not in production.
Configuring local sign-in with vibiz dev
To begin local development, run the CLI command to initialize your local environment:
vibiz devThis command branches the database schema, provisions the development sign-in service, and writes local variables to .env.development.local. The generated file provides the endpoints and secrets your server requires:
VIBIZ_AUTH_BASE_URL: The URL for the development sign-in service.VIBIZ_AUTH_COOKIE_SECRET: The dedicated secret used to sign session cookies locally.VIBIZ_AUTH_JWKS_URL: The public key endpoint for local JSON Web Key Set verification.VIBIZ_AUTH_PROJECT_ID: The project identifier tied to the development environment.
If you prefer not to write files to disk, pass your development startup command directly:
vibiz dev -- npm run devIf your local authentication table becomes cluttered with discarded test accounts, you do not need to delete records manually. Run the reset flag:
vibiz dev --resetThis command discards the development database branch and its users. The next time you run vibiz dev, the platform provisions a clean branch matching your current production schema.
Handling authentication in application code
When using the nextjs-saas template (vibiz init my-app --template nextjs-saas), sign-in endpoints and sessions are wired out of the box. Session checks use currentUser() in lib/auth/server.ts, and the route handler at /api/auth/* manages callback flows.
If you are setting up authentication manually in Next.js or another framework, inspect how session credentials are read. Your server loads environment variables using @vibiz/app:
import { vibiz } from '@vibiz/app';
// Injects VIBIZ_AUTH_BASE_URL and session secrets into process.env
await vibiz.loadEnv();When building sign-up workflows, you can choose between credentials or passwordless routes. Learn more in our guides on email and password sign-in with verification codes and magic link sign-in without building it yourself. For a complete walkthrough of server components and middleware, see how to add sign-in to a Next.js app.
Configuring social providers and settings per environment
Sign-in settings can be inspected and updated independently for each environment using the CLI or the REST API. Adding the --dev flag targets the development environment; omitting it targets production.
Inspecting settings
To review your development sign-in configuration, callback URLs, and enabled providers, run:
vibiz auth --devTo view production settings, run the command without --dev:
vibiz authEnabling social sign-in
For social login, the platform supports google and github. Google sign-in supports shared keys, allowing you to test social login immediately without registering an external OAuth client:
# Enable Google sign-in in development
vibiz auth providers add google --dev
# Enable Google sign-in in production
vibiz auth providers add googleEach environment maintains its own callback_url. The development copy routes authentication callbacks through local handlers, while production requires your live domain.
Restricting email sign-ups
If you are building an internal business tool, you can restrict sign-ups to specific company domains. You can test these rules locally before applying them to production:
# Restrict development sign-ups to company domains
vibiz auth domains acme.com,partner.com --dev
# Remove domain restrictions in development
vibiz auth domains none --devYou can also update settings over HTTP:
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 '{"magic_link":{"enabled":true,"expires_in_minutes":30},"allowed_email_domains":["acme.com"]}'Full configuration details and parameters are documented on the Sign-in page.
Managing production domains and allowed origins
The development sign-in service automatically enables allow_localhost: true and trusts http://localhost:3000. In contrast, the production environment sets allow_localhost: false by default. Production sign-in will reject authentication requests from unauthorized origins.
If your production app is deployed on an external host, you must register the domain so the production sign-in service trusts it:
vibiz domains add app.example.com --elsewhereOnce added, the platform generates a verification TXT record (trust_record). After you add the record to your DNS host, run:
vibiz domains verify app.example.comAlternatively, if you buy a domain directly through thelastapi (vibiz domains buy example.com), DNS records are managed automatically, and the domain is trusted for production sign-in immediately without manual TXT verification. To review external domain connections and standalone services, see Use one service and Domains.
Protecting production credentials with Limited keys
When working with external collaborators or AI coding agents (such as Cursor, Claude Code, or Codex), you should avoid sharing production credentials. thelastapi provides two key permission levels:
- Full-access key: The default access tier for project owners and CI/CD pipelines. Can read and update production secrets, configure domains, and modify production auth settings.
- Limited key: Designed for AI agents and team members. A Limited key defaults to the development environment, can create branches, deploy previews, and modify development sign-in settings, but cannot read production variables or modify live settings.
# Create a limited key for an AI development agent
vibiz keys create dev-agent --limitedIf an agent or team member holding a Limited key attempts to modify production sign-in settings, the API rejects the request:
{
"error": "forbidden",
"status": 403,
"details": {
"reason": "owner_only",
"permission": "auth.production:write",
"grant_url": "https://thelastapi.dev/keys/key_123/allow?permission=auth.production:write"
}
}The key holder receives a grant_url link where the account owner can review the request and explicitly grant the auth.production:write permission if needed. This architecture ensures that agents can adjust development settings freely without the risk of exposing or altering live customer sign-in configurations. For complete details on access controls, visit Keys and environments.
To get started, initialize your project with sign-in and start your local environment with vibiz dev.
Frequently asked questions
Does development sign-in use the same user database as production?
No. Development sign-in uses an isolated database branch that contains your schema but none of your production rows, ensuring test accounts never enter your live customer tables.
Can an AI coding agent accidentally alter production sign-in settings?
No. When configured with a Limited key, agents only have access to the development environment; requests to modify production sign-in settings return a 403 forbidden error requiring owner approval.
Why is my production sign-in rejecting logins from localhost?
Production sign-in sets allow_localhost to false by default and only accepts requests from registered, verified domains, whereas the development environment specifically trusts http://localhost:3000.
What happens to test users when I run vibiz dev --reset?
Running vibiz dev --reset discards the development database branch and wipes all local test users, allowing the next vibiz dev command to provision a clean branch from your current production schema.