Skip to main content

Environment Variables

The platform requires several environment variables for database connections, authentication, external services, and storage backends.

Required Variables

Database

VariableDescriptionExample
REMOTE_URLMongoDB connection stringmongodb+srv://user:pass@cluster.mongodb.net/bahri_moc

Used in: src/helpers/dbConnection.ts

const MONGODB_URI = process.env.REMOTE_URL;

Authentication

VariableDescriptionExample
JWT_SECRETSecret key for signing JWT tokensA strong random string (64+ characters)

Used in: src/middleware.ts (verification) and login API route (signing).

Application URL

VariableDescriptionExample
NEXT_PUBLIC_APP_URLBase URL of the deployed applicationhttps://moc.bahri.sa

Used for constructing links in emails and notifications. The NEXT_PUBLIC_ prefix makes it available in both server and client code.

Email Service

VariableDescriptionExample
EMAIL_LAMBDA_URLAWS Lambda endpoint for email dispatchhttps://xxxxx.lambda-url.eu-north-1.on.aws/

Used in: src/helpers/send_email.ts

File Storage

VariableDescriptionExample
NEXT_PUBLIC_CLOUDINARY_CLOUD_NAMECloudinary account cloud namebahri-moc
NEXT_PUBLIC_CLOUDINARY_UPLOAD_PRESETCloudinary upload presetmoc_uploads
NEXT_PUBLIC_S3_BUCKET_URLAWS S3 bucket URL or Lambda endpointhttps://xxxxx.lambda-url.eu-north-1.on.aws/

Firebase (Real-Time Features)

VariableDescription
NEXT_PUBLIC_FIREBASE_API_KEYFirebase API key
NEXT_PUBLIC_FIREBASE_AUTH_DOMAINFirebase auth domain
NEXT_PUBLIC_FIREBASE_PROJECT_IDFirebase project ID
NEXT_PUBLIC_FIREBASE_STORAGE_BUCKETFirebase storage bucket
NEXT_PUBLIC_FIREBASE_MESSAGING_SENDER_IDFirebase messaging sender ID
NEXT_PUBLIC_FIREBASE_APP_IDFirebase app ID

Used in: src/lib/firebase.js

Setting Up Environment Variables

Local Development

Create a .env.local file in the project root:

REMOTE_URL=mongodb+srv://user:pass@cluster.mongodb.net/bahri_moc
JWT_SECRET=your-secret-key-here
NEXT_PUBLIC_APP_URL=http://localhost:3000
EMAIL_LAMBDA_URL=https://xxxxx.lambda-url.eu-north-1.on.aws/
NEXT_PUBLIC_CLOUDINARY_CLOUD_NAME=your-cloud-name
NEXT_PUBLIC_CLOUDINARY_UPLOAD_PRESET=your-preset
NEXT_PUBLIC_S3_BUCKET_URL=https://your-s3-endpoint
NEXT_PUBLIC_FIREBASE_API_KEY=your-firebase-key
NEXT_PUBLIC_FIREBASE_AUTH_DOMAIN=your-project.firebaseapp.com
NEXT_PUBLIC_FIREBASE_PROJECT_ID=your-project-id
NEXT_PUBLIC_FIREBASE_STORAGE_BUCKET=your-project.appspot.com
NEXT_PUBLIC_FIREBASE_MESSAGING_SENDER_ID=123456789
NEXT_PUBLIC_FIREBASE_APP_ID=1:123456789:web:abcdef

Vercel (Production)

  1. Go to your Vercel project dashboard
  2. Navigate to Settings → Environment Variables
  3. Add each variable listed above
  4. Choose the appropriate environments (Production, Preview, Development)
  5. Redeploy after adding or changing variables

Variable Naming Convention

PrefixVisibilityUsage
NEXT_PUBLIC_Server + ClientExposed to browser JavaScript
No prefixServer onlyAvailable only in API routes, middleware, and server components
caution

Never add NEXT_PUBLIC_ prefix to sensitive values like JWT_SECRET, REMOTE_URL, or EMAIL_LAMBDA_URL. These must remain server-only.