Banata

Platform Operators

Environment Variables

Complete reference for every environment variable you need when self-hosting Banata Auth with Convex and Next.js.

Self-hosted deployments only. This page covers the environment variables required when you run your own Convex + Next.js stack. If you use Banata as a managed service, you can skip this page entirely. Hosted app integrations usually only need BANATA_API_KEY and, optionally, BANATA_AUTH_URL if you use a custom Banata auth domain.

Banata Auth reads environment variables from two separate runtimes: the Convex backend (server-side) and the Next.js frontend. Setting each variable in the right place is essential for everything to work correctly.


Quick Reference

VariableWhere to SetRequiredDescription
BETTER_AUTH_SECRETConvexYesSigns sessions, tokens, and webhooks
SITE_URLConvexYesYour app's public URL
CONVEX_DEPLOYMENT.env.localYesConvex deployment name
NEXT_PUBLIC_CONVEX_URL.env.localYesConvex client URL
NEXT_PUBLIC_CONVEX_SITE_URL.env.localYesConvex HTTP actions URL
NEXT_PUBLIC_SITE_URL.env.localRecommendedApp URL for build-time prerendering
OAuth credentialsConvexIf using social authProvider-specific client ID and secret
RESEND_API_KEYConvexIf sending emailsResend API key
BANATA_JWT_SIGNING_KEY_KMS_IDConvex/secrets managerProductionKMS key for JWT signing custody
BANATA_VAULT_KMS_KEY_IDConvex/secrets managerProductionKMS key for vault encryption custody
SMS/WhatsApp provider credentialsConvex/secrets managerIf using phone OTPProvider-specific phone delivery credentials

Convex Environment Variables

You set these on your Convex deployment with npx convex env set. They're available to your Convex functions via process.env.

Core

VariableRequiredDefaultDescription
BETTER_AUTH_SECRETYesCryptographic secret for signing sessions, tokens, and webhook payloads. Use a strong random string (32+ bytes). Generate one with openssl rand -base64 32.
SITE_URLYesYour app's public URL (e.g., http://localhost:3000 in dev, https://myapp.com in production). Banata uses this for OAuth callback URLs, email links, and cookie configuration.
BANATA_AUTH_APP_SECRETProductionApp-level secret separated from vault and token signing keys.
BANATA_JWT_SIGNING_KEY_KMS_IDProductionKMS/HSM key ID used for JWT signing key custody or wrapping.
BANATA_VAULT_KMS_KEY_IDProductionKMS/HSM key ID used for vault key custody or wrapping.
BANATA_REFRESH_TOKEN_PEPPER_KMS_IDProductionKMS/HSM key or secret reference used to protect refresh token hashes.
BANATA_WEBHOOK_SIGNING_PEPPERProductionServer-side pepper used when deriving per-endpoint webhook secrets.
bash
# Set core variables
npx convex env set BETTER_AUTH_SECRET "$(openssl rand -base64 32)"
npx convex env set SITE_URL "http://localhost:3000"

Social OAuth Providers

You only need to set credentials for the providers you've enabled in your socialProviders configuration.

For hosted Banata projects, setting environment variables in your own app is not enough to register a provider in the Banata dashboard. The provider must also be saved to the project through the dashboard or saveSocialProviderCredential(...).

VariableProviderDescription
GOOGLE_CLIENT_IDGoogleOAuth 2.0 client ID from Google Cloud Console
GOOGLE_CLIENT_SECRETGoogleOAuth 2.0 client secret
GITHUB_CLIENT_IDGitHubOAuth App client ID from GitHub Developer Settings
GITHUB_CLIENT_SECRETGitHubOAuth App client secret
APPLE_CLIENT_IDAppleServices ID from Apple Developer Portal
APPLE_CLIENT_SECRETAppleGenerated JWT client secret (expires every 6 months)
MICROSOFT_CLIENT_IDMicrosoftApplication (client) ID from Azure Portal
MICROSOFT_CLIENT_SECRETMicrosoftClient secret value from Azure Portal
MICROSOFT_TENANT_IDMicrosoftDirectory (tenant) ID, or "common", "organizations", "consumers"
FACEBOOK_CLIENT_IDFacebookApp ID from Meta for Developers
FACEBOOK_CLIENT_SECRETFacebookApp Secret from Meta for Developers
TWITTER_CLIENT_IDTwitter/XOAuth 2.0 Client ID
TWITTER_CLIENT_SECRETTwitter/XOAuth 2.0 Client Secret
DISCORD_CLIENT_IDDiscordApplication Client ID
DISCORD_CLIENT_SECRETDiscordApplication Client Secret
SPOTIFY_CLIENT_IDSpotifyApp Client ID
SPOTIFY_CLIENT_SECRETSpotifyApp Client Secret
TWITCH_CLIENT_IDTwitchApplication Client ID
TWITCH_CLIENT_SECRETTwitchApplication Client Secret
LINKEDIN_CLIENT_IDLinkedInApp Client ID
LINKEDIN_CLIENT_SECRETLinkedInApp Client Secret
bash
# Example: GitHub OAuth
npx convex env set GITHUB_CLIENT_ID "Ov23li..."
npx convex env set GITHUB_CLIENT_SECRET "your-secret"
 
# Example: Google OAuth
npx convex env set GOOGLE_CLIENT_ID "123456.apps.googleusercontent.com"
npx convex env set GOOGLE_CLIENT_SECRET "GOCSPX-..."

Email Provider

VariableRequiredDescription
RESEND_API_KEYIf sending emailsAPI key from Resend. Used for verification emails, password resets, magic links, OTP codes, and invitations.
CLOUDFLARE_EMAIL_API_TOKENIf using Cloudflare Email ServiceAPI token with permission to send email.
CLOUDFLARE_ACCOUNT_IDIf using Cloudflare Email ServiceCloudflare account ID used by the Email Service REST API.
bash
npx convex env set RESEND_API_KEY "re_..."

Tip: You can manage Resend, SendGrid, Amazon SES, Mailgun, Postmark, and Cloudflare Email Service from Emails > Providers.

Phone And WhatsApp OTP Providers

Banata Auth exposes phone OTP state and endpoints. Configure delivery from SMS > Providers, or provide your own delivery function through productionReadiness.sendPhoneOtp.

VariableRequiredDescription
SMS_PROVIDER_API_KEYIf using SMS OTPAPI key for your selected SMS provider.
SMS_PROVIDER_API_SECRETIf required by the providerSecondary secret for providers such as Vonage.
SMS_PROVIDER_ACCOUNT_SIDIf using TwilioTwilio account SID.
SMS_PROVIDER_AUTH_TOKENIf using TwilioTwilio auth token.
SMS_PROVIDER_SENDER_IDIf using SMS OTPSender ID or phone number used for SMS delivery.
SMS_PROVIDER_USERNAMEIf required by the providerUsername for providers such as Africa's Talking.
SMS_PROVIDER_API_BASE_URLIf required by the providerOptional provider endpoint override, for example a Mobitech tenant or portal API URL.
WHATSAPP_CLOUD_API_TOKENIf using WhatsApp OTPMeta WhatsApp Cloud API token or provider token.
WHATSAPP_PHONE_NUMBER_IDIf using WhatsApp OTPWhatsApp sender phone number ID.

Never log raw OTPs, provider tokens, or full phone numbers in production logs.

Production Inventory Evidence

Use testing/auth-production-env-inventory-template.json when you prepare the managed production launch evidence.

For each required variable, record:

  • the runtime that owns the variable
  • whether the value is present
  • the secret-store or deployment metadata, with the value redacted
  • whether the value is scoped to production only
  • notes for any missing, blocked, or rotated value

Then run:

bash
bun run verify:auth-env-inventory-template

Do not paste raw API keys, OAuth secrets, OTPs, cookies, session tokens, refresh tokens, KMS plaintext, or provider credentials into the inventory file. The production gate only accepts redacted inventory and log-review evidence.

Passkeys (WebAuthn)

VariableRequiredDescription
PASSKEY_RP_IDIf using passkeysRelying Party ID (e.g., "localhost" in dev, "myapp.com" in production)
PASSKEY_ORIGINIf using passkeysOrigin URL (e.g., "http://localhost:3000" in dev)
bash
npx convex env set PASSKEY_RP_ID "myapp.com"
npx convex env set PASSKEY_ORIGIN "https://myapp.com"

Managing Convex Variables

bash
# List all variables on your deployment
npx convex env list
 
# Remove a variable
npx convex env unset GITHUB_CLIENT_ID

Next.js Environment Variables (.env.local)

These live in your .env.local file and are available to your Next.js application at build and runtime.

VariableRequiredPublic?Description
CONVEX_DEPLOYMENTYesNoConvex deployment identifier (e.g., dev:your-project-name)
NEXT_PUBLIC_CONVEX_URLYesYesConvex client URL (e.g., https://your-project.convex.cloud)
NEXT_PUBLIC_CONVEX_SITE_URLYesYesConvex HTTP actions URL (e.g., https://your-project.convex.site)
NEXT_PUBLIC_SITE_URLRecommendedYesYour app's URL. Used for building absolute URLs during SSR and prerendering.

Example .env.local

bash
# Convex deployment
CONVEX_DEPLOYMENT=dev:your-deployment-name
NEXT_PUBLIC_CONVEX_URL=https://your-deployment.convex.cloud
NEXT_PUBLIC_CONVEX_SITE_URL=https://your-deployment.convex.site
 
# App URL
NEXT_PUBLIC_SITE_URL=http://localhost:3000

Local Development

When you run Convex locally with npx convex dev, your .env.local should point to the local endpoints:

bash
CONVEX_DEPLOYMENT=local:local-your-project-name
NEXT_PUBLIC_CONVEX_URL=http://127.0.0.1:3210
NEXT_PUBLIC_CONVEX_SITE_URL=http://127.0.0.1:3211
NEXT_PUBLIC_SITE_URL=http://localhost:3000

NEXT_PUBLIC_ Safety Reminder

Any variable prefixed with NEXT_PUBLIC_ gets embedded in your client-side JavaScript bundle and is visible to every user. Never put secrets in NEXT_PUBLIC_ variables.

Safe for NEXT_PUBLIC_Never use NEXT_PUBLIC_ for
Convex URLBETTER_AUTH_SECRET
Site URLAPI keys
Feature flagsOAuth secrets

Production Checklist

Before you go live, walk through each item:

  • BETTER_AUTH_SECRET is a unique, strong random value (different from development)
  • SITE_URL points to your production domain (e.g., https://myapp.com)
  • NEXT_PUBLIC_CONVEX_URL points to your production Convex deployment
  • NEXT_PUBLIC_CONVEX_SITE_URL points to your production Convex site URL
  • OAuth callback URLs in each provider's dashboard are updated to production URLs
  • PASSKEY_RP_ID is your production domain (not localhost)
  • PASSKEY_ORIGIN is your production origin (with https://)
  • Email provider API key is set and verified
  • No development secrets are reused in production
  • .env.local is listed in .gitignore (never commit secrets)

Template .env.local

Copy this into your project as a starting point:

bash
# Convex deployment (filled automatically by `npx convex dev`)
CONVEX_DEPLOYMENT=dev:your-deployment-name
NEXT_PUBLIC_CONVEX_URL=https://your-deployment.convex.cloud
NEXT_PUBLIC_CONVEX_SITE_URL=https://your-deployment.convex.site
 
# App URL
NEXT_PUBLIC_SITE_URL=http://localhost:3000

Then set your Convex-side variables:

bash
npx convex env set BETTER_AUTH_SECRET "$(openssl rand -base64 32)"
npx convex env set SITE_URL "http://localhost:3000"
# Add OAuth and email provider secrets as needed

Next Steps