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

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.
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.
bash
npx convex env set RESEND_API_KEY "re_..."

Tip: Resend is the default, but you can swap in any email provider (SendGrid, Postmark, Mailgun, etc.) by changing the fetch() call in your email callbacks.

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