This guide covers deploying the authentication microservice to various platforms.
- All environment variables configured
- Database tables created in Supabase
- JWT secret generated (minimum 32 characters)
- Email service configured and tested
- OAuth credentials obtained (if using Google/Azure)
- CORS origins configured for production
- SSL/TLS certificates ready (for HTTPS)
- Monitoring and logging configured
npm install -g herokuheroku loginheroku create channeling-auth-serviceheroku config:set NODE_ENV=production
heroku config:set PORT=3000
heroku config:set SUPABASE_URL=your-supabase-url
heroku config:set SUPABASE_SERVICE_ROLE_KEY=your-service-role-key
heroku config:set JWT_SECRET=your-jwt-secret
heroku config:set EMAIL_USER=your-email@gmail.com
heroku config:set EMAIL_PASS=your-app-password
# ... set all other env variablesgit push heroku mainheroku ps:scale web=1pip install awsebclieb init -p node.js channeling-auth-service --region us-east-1eb create production-enveb setenv NODE_ENV=production \
SUPABASE_URL=your-url \
JWT_SECRET=your-secret \
# ... all other variableseb deploydocker build -t gcr.io/your-project-id/channeling-auth:latest .docker push gcr.io/your-project-id/channeling-auth:latestgcloud run deploy channeling-auth-service \
--image gcr.io/your-project-id/channeling-auth:latest \
--platform managed \
--region us-central1 \
--allow-unauthenticated \
--set-env-vars "NODE_ENV=production,SUPABASE_URL=your-url,JWT_SECRET=your-secret"az webapp create \
--resource-group your-resource-group \
--plan your-app-service-plan \
--name channeling-auth-service \
--runtime "NODE|18-lts"az webapp config appsettings set \
--resource-group your-resource-group \
--name channeling-auth-service \
--settings NODE_ENV=production SUPABASE_URL=your-url JWT_SECRET=your-secretaz webapp deployment source config-zip \
--resource-group your-resource-group \
--name channeling-auth-service \
--src ./dist.zipname: channeling-auth-service
services:
- name: api
github:
repo: your-username/user-service
branch: main
build_command: npm run build
run_command: npm run start:prod
envs:
- key: NODE_ENV
value: production
- key: SUPABASE_URL
value: ${SUPABASE_URL}
- key: JWT_SECRET
value: ${JWT_SECRET}
http_port: 3000doctl apps create --spec app.yaml# Build stage
FROM node:18-alpine AS builder
WORKDIR /app
COPY package*.json ./
RUN npm ci
COPY . .
RUN npm run build
# Production stage
FROM node:18-alpine
WORKDIR /app
COPY package*.json ./
RUN npm ci --only=production
COPY --from=builder /app/dist ./dist
EXPOSE 3000
CMD ["node", "dist/main"]node_modules
dist
npm-debug.log
.env
.git
.gitignore
README.md
.vscode
# Build
docker build -t channeling-auth:latest .
# Run
docker run -p 3000:3000 \
-e NODE_ENV=production \
-e SUPABASE_URL=your-url \
-e JWT_SECRET=your-secret \
channeling-auth:latestversion: '3.8'
services:
auth-service:
build: .
ports:
- "3000:3000"
env_file:
- .env.production
restart: unless-stopped
healthcheck:
test: ["CMD", "wget", "--quiet", "--tries=1", "--spider", "http://localhost:3000/health"]
interval: 30s
timeout: 10s
retries: 3- Use secure vaults (AWS Secrets Manager, Azure Key Vault, etc.)
- Never commit
.envfiles - Rotate secrets regularly
// main.ts - Force HTTPS in production
if (process.env.NODE_ENV === 'production') {
app.use((req, res, next) => {
if (req.header('x-forwarded-proto') !== 'https') {
res.redirect(`https://${req.header('host')}${req.url}`);
} else {
next();
}
});
}// Increase rate limiting for production
ThrottlerModule.forRoot([{
ttl: 60000,
limit: 100, // More lenient for production
}])// Configure specific origins
app.enableCors({
origin: [
'https://yourdomain.com',
'https://app.yourdomain.com'
],
credentials: true,
});// Use production-grade logger
import * as winston from 'winston';
const logger = winston.createLogger({
level: 'info',
format: winston.format.json(),
transports: [
new winston.transports.File({ filename: 'error.log', level: 'error' }),
new winston.transports.File({ filename: 'combined.log' }),
],
});Add to app.controller.ts:
@Get('health')
async healthCheck() {
return {
status: 'ok',
timestamp: new Date().toISOString(),
uptime: process.uptime(),
};
}- Application Performance: New Relic, Datadog
- Error Tracking: Sentry, Rollbar
- Logging: ELK Stack, Loggly, Papertrail
- Uptime Monitoring: Pingdom, UptimeRobot
Create .github/workflows/deploy.yml:
name: Deploy to Production
on:
push:
branches: [main]
jobs:
deploy:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Setup Node.js
uses: actions/setup-node@v2
with:
node-version: '18'
- name: Install dependencies
run: npm ci
- name: Run tests
run: npm test
- name: Build
run: npm run build
- name: Deploy to Heroku
uses: akhileshns/heroku-deploy@v3.12.12
with:
heroku_api_key: ${{ secrets.HEROKU_API_KEY }}
heroku_app_name: "channeling-auth-service"
heroku_email: "your-email@example.com"-
Test Health Endpoint
curl https://your-domain.com/health
-
Test Authentication
curl -X POST https://your-domain.com/api/auth/login \ -H "Content-Type: application/json" \ -d '{"email":"test@example.com","password":"Test@123"}'
-
Verify Swagger Docs
https://your-domain.com/api/docs -
Check Logs
# Heroku heroku logs --tail # AWS eb logs # Docker docker logs <container-id>
-
502 Bad Gateway
- Check if app is listening on correct PORT
- Verify environment variables are set
-
Database Connection Failed
- Verify Supabase credentials
- Check network connectivity
-
Email Not Sending
- Verify Gmail App Password
- Check firewall rules
-
OAuth Redirect Issues
- Update callback URLs in Google/Azure console
- Check HTTPS configuration
For deployment issues:
- Check application logs
- Review environment variables
- Verify database connectivity
- Test API endpoints manually
- Contact DevOps team
- Enable Caching: Use Redis for session/OTP storage
- Database Indexing: Ensure proper indexes on Supabase
- Compression: Enable gzip compression
- CDN: Use CDN for static assets
- Load Balancing: Use multiple instances behind load balancer
Last Updated: 2025