Skip to content

Environment Setup โ€” Quick Start Guide โ€‹

Time to complete: ~20 minutes

Follow these steps in order to get your local development environment running and deployments configured.


Environment Detection Pattern โ€‹

IMPORTANT: When adding dev-only features (debug panels, simulate buttons, etc.), use hostname-based detection:

javascript
const hostname = typeof window !== 'undefined' ? window.location.hostname : ''
const isProductionEnv = import.meta.env.VITE_APP_ENV === 'production' || hostname === 'ourlantern.app'
const isDev = !isProductionEnv

Why hostname check?

  • import.meta.env.DEV only works on localhost (Vite dev server)
  • Deployed dev sites (dev.ourlantern.app) need hostname detection
  • Production site (ourlantern.app) should hide all dev features

Examples in codebase:

  • src/screens/dashboard/Dashboard.jsx - "Simulate Wave" button
  • src/screens/profile/ProfileSettings.jsx - Location spoof panel
  • src/firebase.js - Firebase environment logging

Step-by-Step Checklist โ€‹

โœ… Step 1: Install Dependencies (2 min) โ€‹

bash
cd lantern_app
npm install

Verify: Run npm --version โ€” should show v8 or higher.


โœ… Step 2: Create Firebase DEV Project (5 min) โ€‹

  1. Go to https://console.firebase.google.com
  2. Click "Add project"
  3. Name: lantern-app-dev
  4. Disable Google Analytics (or enable if you want)
  5. Click "Create project"

Wait for project to be created (~1 minute).


โœ… Step 3: Enable Firebase Services in DEV (3 min) โ€‹

In your lantern-app-dev project:

Authentication:

  1. Click "Authentication" in left sidebar
  2. Click "Get started"
  3. Click "Email/Password"
  4. Enable the toggle
  5. Click "Save"

Firestore Database:

  1. Click "Firestore Database"
  2. Click "Create database"
  3. Choose "Start in test mode"
  4. Select region (e.g., us-central1)
  5. Click "Enable"

Storage:

  1. Click "Storage"
  2. Click "Get started"
  3. Start in test mode
  4. Click "Next" โ†’ "Done"

โœ… Step 4: Get Firebase DEV Config (2 min) โ€‹

  1. In Firebase Console, click โš™๏ธ (gear icon) โ†’ "Project settings"
  2. Scroll down to "Your apps"
  3. Click web icon </> (if no apps exist)
  4. App nickname: "Lantern Dev"
  5. Click "Register app"
  6. COPY the config object that looks like:
javascript
const firebaseConfig = {
  apiKey: "AIzaSy...",
  authDomain: "lantern-app-dev.firebaseapp.com",
  projectId: "lantern-app-dev",
  storageBucket: "lantern-app-dev.appspot.com",
  messagingSenderId: "123456789",
  appId: "1:123456789:web:abc..."
};

โš ๏ธ Keep this open โ€” you'll need it in the next step!


โœ… Step 5: Set Up Local Environment File (2 min) โ€‹

In your terminal:

bash
# Copy the example file
cp .env.local.example .env.local

Open .env.local in your editor and paste your Firebase config values:

bash
VITE_FIREBASE_API_KEY=AIzaSy...  # Copy from firebaseConfig.apiKey
VITE_FIREBASE_AUTH_DOMAIN=lantern-app-dev.firebaseapp.com
VITE_FIREBASE_PROJECT_ID=lantern-app-dev
VITE_FIREBASE_STORAGE_BUCKET=lantern-app-dev.appspot.com
VITE_FIREBASE_MESSAGING_SENDER_ID=123456789
VITE_FIREBASE_APP_ID=1:123456789:web:abc...
VITE_APP_ENV=local

# OPTIONAL: Development Location Spoofing
# For testing venue-based features without leaving home
# Format: "latitude,longitude" (no spaces)
# Example: VITE_DEV_TEST_LOCATION="40.7128,-74.0060"
VITE_DEV_TEST_LOCATION=""

Save the file.


๐Ÿงช Optional: Location Spoofing for Development โ€‹

Lantern includes location-based features (check-ins, nearby users, venue offers). To test these features without physically visiting venues, you can spoof your location in development.

Two ways to set your test location:

Option 1: Environment Variable (Auto-loads on startup) โ€‹

In .env.local, set your test coordinates:

bash
VITE_DEV_TEST_LOCATION="40.7128,-74.0060"

Get coordinates from Google Maps:

  1. Right-click any location on Google Maps
  2. Click the coordinates that appear (e.g., "40.7128, -74.0060")
  3. They'll copy to your clipboard
  4. Paste into .env.local

Restart dev server for changes to take effect.

Option 2: Debug Panel (Change on-the-fly) โ€‹

When running in development mode (npm run dev):

  1. Go to Profile Settings (#/profile)
  2. Click the "Privacy" tab
  3. Scroll down to see the purple "๐Ÿšง Dev: Location Spoofing" panel
  4. Enter latitude and longitude
  5. Click "Set Location"

The spoofed location persists in localStorage until you clear it.

Tip: Spoof your location to:

  • Your home address (for testing from home)
  • A local bar/venue (test venue check-ins)
  • Different cities (test geographic features)

โš ๏ธ Location spoofing is only available in development mode โ€” production builds automatically use real geolocation.


โœ… Step 6: Test Local Development (1 min) โ€‹

bash
npm run dev

Open browser to http://localhost:5173

Verify:

  • App loads without errors
  • Open browser console (F12)
  • Look for: ๐Ÿ”ฅ Firebase initialized (local environment)
  • Check it says Project: lantern-app-dev

โœ… Success! Your local environment is working!

Press Ctrl+C to stop the dev server.


โœ… Step 7: Create Firebase PRODUCTION Project (5 min) โ€‹

Repeat Steps 2-4 but name the project lantern-app-prod:

  1. Firebase Console โ†’ Add project
  2. Name: lantern-app-prod
  3. Enable Authentication, Firestore, Storage (same as dev)
  4. Get the config (โš™๏ธ โ†’ Project settings โ†’ Add web app โ†’ "Lantern Prod")

โš ๏ธ Save both configs (dev AND prod) โ€” you'll need them for Cloudflare.


โœ… Step 8: Set Up Cloudflare Pages (10 min) โ€‹

Prerequisites: Have your GitHub repo cattreedev/lantern_app ready.

8.1: Create Cloudflare Pages Project โ€‹

  1. Go to https://dash.cloudflare.com
  2. Click "Pages" in left sidebar
  3. Click "Create a project"
  4. Click "Connect to Git"
  5. Authorize GitHub (if needed)
  6. Select repository: cattreedev/lantern_app
  7. Click "Begin setup"

8.2: Configure Build Settings โ€‹

  • Project name: lantern-app
  • Production branch: main
  • Build command: npm run build
  • Build output directory: dist
  • Root directory: (leave empty or /)

Click "Save and Deploy" (it will fail first time โ€” that's OK!)

8.3: Set Environment Variables โ€‹

  1. Go to your Cloudflare Pages project
  2. Click "Settings" โ†’ "Environment variables"

For Production (main branch):

Click "Add variable" for each of these (using your lantern-app-prod config):

Variable NameValue (from lantern-app-prod)
VITE_FIREBASE_API_KEYAIzaSy... (prod)
VITE_FIREBASE_AUTH_DOMAINlantern-app-prod.firebaseapp.com
VITE_FIREBASE_PROJECT_IDlantern-app-prod
VITE_FIREBASE_STORAGE_BUCKETlantern-app-prod.appspot.com
VITE_FIREBASE_MESSAGING_SENDER_ID123... (prod)
VITE_FIREBASE_APP_ID1:123... (prod)
VITE_APP_ENVproduction
NODE_VERSION20

For Preview (all other branches):

Repeat above, but use values from lantern-app-dev config:

Variable NameValue (from lantern-app-dev)
VITE_FIREBASE_API_KEYAIzaSy... (dev)
VITE_FIREBASE_AUTH_DOMAINlantern-app-dev.firebaseapp.com
VITE_FIREBASE_PROJECT_IDlantern-app-dev
VITE_FIREBASE_STORAGE_BUCKETlantern-app-dev.appspot.com
VITE_FIREBASE_MESSAGING_SENDER_ID123... (dev)
VITE_FIREBASE_APP_ID1:123... (dev)
VITE_APP_ENVdevelopment
NODE_VERSION20

Click "Save"


โœ… Step 9: Trigger First Deployment โ€‹

In your terminal:

bash
# Make a small change to trigger deployment
echo "# Deployment test" >> README.md

# Commit and push
git add .
git commit -m "Configure deployment environment"
git push origin main

Wait ~2 minutes for build.

Go to Cloudflare Pages โ†’ "Deployments" to watch progress.

โœ… Success! When build completes, visit your production URL!


โœ… Step 10: Create Dev Branch โ€‹

bash
# Create dev branch from main
git checkout -b dev
git push origin dev

In Cloudflare Pages:

  1. Go to Settings โ†’ Builds & deployments
  2. Verify "Preview deployments" is enabled for all branches

Now when you push to dev, it auto-deploys to a preview URL!


๐ŸŽ‰ You're Done! โ€‹

What You Just Set Up โ€‹

  • โœ… Local development environment
  • โœ… Two Firebase projects (dev + prod)
  • โœ… Cloudflare Pages automatic deployments
  • โœ… Environment-specific configurations
  • โœ… Git branch strategy (main for prod, dev for staging)

Your Workflow Now โ€‹

Daily development:

bash
# 1. Work locally
npm run dev

# 2. Commit changes
git add .
git commit -m "Add feature"

# 3. Push to dev branch
git push origin dev
# โ†’ Auto-deploys to preview URL for testing

# 4. When ready, merge to main
git checkout main
git merge dev
git push origin main
# โ†’ Auto-deploys to production!

Common Issues & Fixes โ€‹

Build fails on Cloudflare:

  • Check you set NODE_VERSION=20
  • Verify all VITE_* variables are set
  • Check build logs in Cloudflare dashboard

"Firebase not initialized" error:

  • Verify environment variables in Cloudflare
  • Ensure variable names start with VITE_
  • Check spelling/typos in variable names

Wrong Firebase project connecting:

  • Check which branch you're on
  • Verify Cloudflare environment variables for Production vs Preview
  • Look in browser console for "Firebase initialized" message

Next Steps โ€‹

Now that environment is set up:

  1. ๐Ÿ“– Read DEPLOYMENT.md for full deployment guide
  2. ๐Ÿ”’ Add Firebase Security Rules (don't leave in test mode!)
  3. ๐Ÿ” Set up Cloudflare Access for password protection
  4. ๐Ÿš€ Start building features!

Need help? Check docs/engineering/ or open an issue!

Built with VitePress