All hardcoded URLs have been removed. All configuration now comes from environment variables.
Create a .env file in the backend/ directory with the following variables:
# Application Environment
APP_ENV=dev
# Database
DB_URL=postgresql://user:password@localhost:5432/grainlify?sslmode=disable
# JWT Secret (generate a secure random string)
JWT_SECRET=your-secret-key-here
# GitHub OAuth
GITHUB_OAUTH_CLIENT_ID=your-github-oauth-client-id
GITHUB_OAUTH_CLIENT_SECRET=your-github-oauth-client-secret
# IMPORTANT: This must be the FULL callback URL and must match EXACTLY what's registered in your GitHub OAuth app
# The callback route is: /auth/github/login/callback
# Development: http://localhost:8080/auth/github/login/callback
# Production: https://your-backend-domain.com/auth/github/login/callback
# If not set, will be constructed from PUBLIC_BASE_URL + /auth/github/login/callback
GITHUB_OAUTH_REDIRECT_URL=http://localhost:8080/auth/github/login/callback# Frontend Base URL - Used for OAuth redirects
# Development: http://localhost:5173
# Production: https://your-frontend-domain.com
FRONTEND_BASE_URL=http://localhost:5173
# Optional: Explicit OAuth success redirect (if different from FRONTEND_BASE_URL/auth/callback)
GITHUB_LOGIN_SUCCESS_REDIRECT_URL=http://localhost:5173/auth/callback
# CORS Origins (comma-separated, optional - defaults to FRONTEND_BASE_URL)
# Development: http://localhost:5173,http://localhost:3000
# Production: https://your-frontend-domain.com
CORS_ORIGINS=http://localhost:5173# Server Configuration
PORT=8080
LOG_LEVEL=info
AUTO_MIGRATE=true
# Public Base URL (for webhooks)
PUBLIC_BASE_URL=http://localhost:8080
# Token Encryption Key (32 bytes base64 encoded)
TOKEN_ENC_KEY_B64=your-32-byte-base64-encryption-key
# GitHub Webhook Secret
GITHUB_WEBHOOK_SECRET=your-github-webhook-secret
# Didit KYC
DIDIT_API_KEY=your-didit-api-key
DIDIT_WORKFLOW_ID=your-didit-workflow-id
DIDIT_WEBHOOK_SECRET=your-didit-webhook-secret
# NATS (optional, for event bus)
NATS_URL=Create a .env file in the frontend/ directory with the following variables:
# Backend API URL
# Development: http://localhost:8080
# Production: https://your-backend-domain.com
VITE_API_BASE_URL=http://localhost:8080# Frontend Base URL (optional, defaults to window.location.origin)
# Development: http://localhost:5173
# Production: https://your-frontend-domain.com
VITE_FRONTEND_BASE_URL=http://localhost:5173-
GitHub Login Success Redirect:
- First checks
GITHUB_LOGIN_SUCCESS_REDIRECT_URL(if set) - Otherwise, constructs from
FRONTEND_BASE_URL+/auth/callback - Example:
FRONTEND_BASE_URL=http://localhost:5173→ redirects tohttp://localhost:5173/auth/callback
- First checks
-
CORS Configuration:
- If
CORS_ORIGINSis set, uses those exact origins (comma-separated) - Otherwise, dynamically allows:
- All
http://localhost:*andhttp://127.0.0.1:*origins - The
FRONTEND_BASE_URLorigin
- All
- If
VITE_API_BASE_URL: Points to your backend serverVITE_FRONTEND_BASE_URL: Used for constructing callback URLs (defaults to current origin)
-
Backend
.env:FRONTEND_BASE_URL=http://localhost:5173 GITHUB_LOGIN_SUCCESS_REDIRECT_URL=http://localhost:5173/auth/callback CORS_ORIGINS=http://localhost:5173
-
Frontend
.env:VITE_API_BASE_URL=http://localhost:8080 VITE_FRONTEND_BASE_URL=http://localhost:5173
-
Backend
.env:FRONTEND_BASE_URL=https://your-frontend-domain.com GITHUB_LOGIN_SUCCESS_REDIRECT_URL=https://your-frontend-domain.com/auth/callback CORS_ORIGINS=https://your-frontend-domain.com
-
Frontend
.env:VITE_API_BASE_URL=https://your-backend-domain.com VITE_FRONTEND_BASE_URL=https://your-frontend-domain.com
- No hardcoded URLs: All URLs are now configurable via environment variables
- Vite prefix: Frontend environment variables must be prefixed with
VITE_to be accessible in the browser - CORS: The backend automatically allows localhost origins in development mode
- Fallbacks: If
FRONTEND_BASE_URLis not set, redirects may fail - always set it!
CRITICAL: The GITHUB_OAUTH_REDIRECT_URL must match EXACTLY what's registered in your GitHub OAuth app settings.
-
Check your current
GITHUB_OAUTH_REDIRECT_URLvalue:# In your backend .env file, it should be: GITHUB_OAUTH_REDIRECT_URL=http://localhost:8080/auth/github/login/callback -
Register the exact URL in GitHub:
- Go to GitHub → Settings → Developer settings → OAuth Apps
- Select your OAuth app
- In "Authorization callback URL", add:
http://localhost:8080/auth/github/login/callback - The URL must match EXACTLY (including http vs https, localhost vs 127.0.0.1, port number, and path)
-
Common mistakes:
- ❌
http://127.0.0.1:8080(should belocalhost) - ❌
http://localhost:8080(missing/auth/github/login/callbackpath) - ❌
http://localhost:8080/callback(wrong path) - ✅
http://localhost:8080/auth/github/login/callback(correct)
- ❌
-
Auto-construction fallback:
- If
GITHUB_OAUTH_REDIRECT_URLis not set, it will be constructed fromPUBLIC_BASE_URL + /auth/github/login/callback - Example:
PUBLIC_BASE_URL=http://localhost:8080→http://localhost:8080/auth/github/login/callback
- If
Make sure to:
- Set
GITHUB_OAUTH_REDIRECT_URLto your production backend URL - Register the same URL in your GitHub OAuth app settings
- Use
https://(nothttp://) for production