Prerequisites
Before deploying to Vercel:- GitHub, GitLab, or Bitbucket repository with Invoice Generator code
- Turso database created and migrated
- Google OAuth credentials configured
- Vercel account (free tier available)
Deployment steps
Import repository
Navigate to Vercel’s import page and import your Git repository.
Configure project settings
Vercel automatically detects Next.js configuration:
- Framework Preset: Next.js
- Build Command:
npm run build(frompackage.json:7) - Output Directory:
.next(default) - Install Command:
npm install - Node.js Version: 20.x or later
Add environment variables
In the Vercel dashboard, add all required environment variables:Database
TURSO_DATABASE_URL- Your Turso database URLTURSO_AUTH_TOKEN- Turso authentication token
AUTH_SECRET- Random secret for NextAuth.js (generate withopenssl rand -base64 32)GOOGLE_CLIENT_ID- Google OAuth Client IDGOOGLE_CLIENT_SECRET- Google OAuth Client Secret
Configure OAuth redirect URI
Add Vercel deployment URL to Google OAuth settings:Update both development and production authorized redirect URIs in Google Cloud Console.
Run database migration
After deployment, run the migration script to set up your database schema:This executes
scripts/migrate.mjs:1-27 which creates tables from app/lib/schema.sql.Post-deployment configuration
Custom domain
Add a custom domain in Vercel dashboard:- Navigate to Settings > Domains
- Add your domain name
- Configure DNS records as instructed
- Update Google OAuth redirect URIs with new domain
Environment-specific variables
Vercel supports environment-specific configuration:- Production - Variables used in production deployments
- Preview - Variables for preview deployments from pull requests
- Development - Variables for local development with
vercel dev
Set different
TURSO_DATABASE_URL values for production and preview environments to avoid data conflicts.Automatic deployments
Vercel automatically deploys:- Production - Commits to your main/master branch
- Preview - Pull requests and commits to other branches
Build optimization
The Next.js configuration (next.config.ts:3-18) is optimized for Vercel:
- Turbopack enabled for faster builds
- bcryptjs marked as server-only package for smaller client bundles
- Image domains configured for Google profile pictures
Troubleshooting
Build failures
Error: Module not foundRuntime errors
Authentication not working Verify:AUTH_SECRETis set in environment variables- Google OAuth redirect URI matches exactly:
https://your-domain.com/api/auth/callback/google GOOGLE_CLIENT_IDandGOOGLE_CLIENT_SECRETare correct
TURSO_DATABASE_URLformat is correct (should start withlibsql://)TURSO_AUTH_TOKENis set (optional for local databases, required for remote)- Database exists and is accessible from Vercel’s network
Migration issues
If migrations fail:Monitoring and analytics
Vercel provides built-in monitoring:- Analytics - Page views, visitor metrics, and Web Vitals
- Logs - Real-time function logs and errors
- Speed Insights - Performance monitoring
Scaling considerations
Vercel automatically scales based on traffic:- Serverless functions - Auto-scale to handle concurrent requests
- Edge Network - Global CDN for static assets
- Database - Scale Turso separately using edge replicas
Free tier includes 100GB bandwidth and 100 hours of serverless function execution. Monitor usage in Vercel dashboard.
Security best practices
- Environment variables - Never expose secrets in client-side code
- Preview deployments - Use separate databases for preview branches
- Authentication - Regenerate
AUTH_SECRETif compromised - OAuth - Restrict OAuth redirect URIs to known domains only
CI/CD integration
Vercel integrates with GitHub Actions for advanced workflows:Next steps
Environment variables
Complete reference for all environment variables
Self-hosted option
Alternative deployment on your infrastructure