Skip to main content

Configuration

This section covers the environment configuration required to run the Cosailor Template in different environments.

Security Best Practices for Secrets

  1. Never commit secrets to version control
  2. Use environment variables for all sensitive data
  3. Generate strong secrets:
    # Generate a strong JWT secret or auth secret
    openssl rand -hex 32

Web Frontend Configuration (Next.js)

  • Client-side variables (NEXT_PUBLIC_*) - Available in the browser
  • Server-side variables - Only available on the server

Required Environment Variables

Create a .env.local file in the apps/web directory:

# OAuth Configuration
AUTH_GOOGLE_ID=<your-google-oauth-client-id>
AUTH_GOOGLE_SECRET=<your-google-oauth-client-secret>

# Auth.js Configuration
AUTH_SECRET=<random-secret-string>
AUTH_TRUST_HOST=true
AUTH_URL=http://localhost:3000/api/auth

CORE_API_URL=http://localhost:8000
CHAT_API_URL=http://localhost:8001

OAuth Provider Setup

  1. Google OAuth:

    • Go to Google Cloud Console
    • Create a new project or select existing one
    • Enable Google+ API
    • Create OAuth 2.0 credentials
    • Add authorized redirect URIs:
      • http://localhost:3000/api/auth/callback/google (development)
      • http://yourdomain.com/api/auth/callback/google (production)
  2. Auth.js Configuration:

    • AUTH_SECRET: Generate a random string (32+ characters recommended)
    • AUTH_TRUST_HOST: Set to true to trust the host
    • AUTH_URL: The base URL where your auth endpoints are served

Core API Configuration

Required Environment Variables

Create a .env file in the apps/core-api directory:

# Database Configuration
DATABASE_URL=postgresql://username:password@localhost:5432/cosailor_db
DB_SCHEMA=public

# JWT Configuration
CORE_API_JWT_SECRET=<your-jwt-secret-key>

Database Setup

  1. Install PostgreSQL:

  2. Run Migrations:

    cd apps/core-api
    DATABASE_URL="postgresql://..." alembic -c src/db/alembic.ini upgrade head
  3. Seed Test Data (Optional):

    DATABASE_URL="postgresql://..." python src/scripts/seed_auth_data.py