Unstack Pro Docs

Deployment

Deploy Unstack Pro to production

Deployment

Deploy to production in minutes. Auth is already configured just set your production environment variables and go live.

No auth configuration needed for deployment. Just connect services with production credentials.

Prerequisites

Before deploying, ensure you have:

  • Completed local development setup
  • Convex account and project
  • Resend account for email sending
  • Autumn account for billing
  • Vercel account (free tier works)
  • Domain name (optional but recommended)
  • All environment variables documented

Deployment Steps

Prepare Your Repository

  1. Commit all changes:

    git add .
    git commit -m "Ready for deployment"
  2. Push to GitHub:

    git push origin main
  3. Verify .gitignore includes:

    • .env.local
    • .env
    • node_modules/
    • .next/

Configure Convex for Production

  1. Go to your Convex dashboard: dashboard.convex.dev

  2. Create production deployment:

    • Click your project
    • Go to "Settings"
    • Note your production deployment name
  3. Set production environment variables:

    • Copy your entire .env file
    • Go to "Settings" > "Environment Variables" tab
    • Paste variables, updating:
      • CONVEX_DEPLOYMENT to prod:your-deployment-name
      • NEXT_PUBLIC_CONVEX_URL and NEXT_PUBLIC_CONVEX_SITE_URL to production URLs
      • NEXT_PUBLIC_APP_URL to your production domain
  4. Save changes

Use different secrets for production! Never reuse development secrets.

Deploy to Vercel

  1. Go to vercel.com

  2. Import your repository:

    • Click "New Project"
    • Import from GitHub
    • Select your repository
  3. Configure project:

    • Framework Preset: Next.js
    • Root Directory: ./
    • Build Command: next build
    • Output Directory: .next
  4. Add environment variables:

    Go to "Environment Variables" and add paste your .env variables, updating for production as needed:

    • BETTER_AUTH_SECRET: New secure value
    • BETTER_AUTH_URL: Your production domain
    • NEXT_PUBLIC_APP_URL: Your production domain
    • NEXT_PUBLIC_APP_NAME: Your application name
    • PASSKEY_RP_ID: Your production domain
    • CONVEX_DEPLOYMENT: prod:your-deployment-name
    • NEXT_PUBLIC_CONVEX_URL: Production Convex URL
    • NEXT_PUBLIC_CONVEX_SITE_URL: Production Convex Site URL

Critical: BETTER_AUTH_SECRET must be different from development and properly generated with openssl rand -base64 32.

  1. Generate JWKS keys for production:
    bunx convex run betterAuth/auth:rotateKeys --prod | bunx convex env set JWKS --prod

JWKS key rotation will log out all existing users. Run this during low-traffic periods.

Prerequisite: Ensure you've run npx convex dev at least once to push the betterAuth/auth:rotateKeys function to your deployment before running this command.

  1. Deploy:
    • Click "Deploy"
    • Wait for build to complete (2-3 minutes)
    • Vercel will provide a URL

Configure Custom Domain (Optional)

  1. In Vercel project settings:

    • Go to "Domains"
    • Add your domain
    • Follow DNS instructions
  2. Update environment variables:

    BETTER_AUTH_URL=https://yourdomain.com
    NEXT_PUBLIC_APP_URL=https://yourdomain.com
    PASSKEY_RP_ID=yourdomain.com
  3. Update Convex environment:

    npx convex env set BETTER_AUTH_URL "https://yourdomain.com" --prod

DNS changes can take up to 48 hours but usually propagate within minutes.

Verify Deployment

  1. Visit your production URL

  2. Test authentication:

    • Register a new account
    • Check email verification
    • Test OTP login
    • Try passkey (if on HTTPS)
  3. Check Convex:

    • Go to Convex dashboard
    • Verify data is being created
    • Check production deployment logs
  4. Test key features:

    • Create organization
    • Invite members
    • Test 2FA
    • Verify admin panel (if applicable)

Post-Deployment

Set Up Email Domain

For production emails, configure your domain in Resend:

  1. Add domain in Resend dashboard
  2. Add DNS records provided by Resend
  3. Verify domain
  4. Update EMAIL_FROM to use your domain

Until domain is verified, emails may go to spam or fail to send.

Configure Billing

If using Autumn for payments:

  1. Set up Autumn account
  2. Get production API key
  3. Add AUTUMN_API_KEY to Vercel
  4. Test payment flows

Set Up Monitoring (Optional)

Configure Sentry for error tracking:

  1. Create Sentry project
  2. Get DSN from Sentry dashboard
  3. Configure in these files:
    • instrumentation.ts (server-side)
    • instrumentation-client.ts (client-side)
    • sentry.edge.config.ts (edge runtime)
    • sentry.server.config.ts (server-side config)

Sentry configuration is done in code files, not environment variables. You can use the Sentry Wizard (@sentry/wizard) to help set this up.

Environment Variables Checklist

Required for production:

  • BETTER_AUTH_SECRET (new, secure value)
  • BETTER_AUTH_URL (your domain)
  • NEXT_PUBLIC_APP_URL (your domain)
  • NEXT_PUBLIC_APP_NAME (your app name)
  • CONVEX_DEPLOYMENT (production)
  • NEXT_PUBLIC_CONVEX_URL (production)
  • NEXT_PUBLIC_CONVEX_SITE_URL (production)
  • PASSKEY_RP_ID (your domain)
  • RESEND_API_KEY (production key)
  • EMAIL_FROM (verified domain)
  • AUTUMN_API_KEY (optional, required only for organization billing)
  • JWKS (generated with bunx convex run betterAuth/auth:rotateKeys --prod | bunx convex env set JWKS --prod)

Optional:

  • Configure Sentry in code files (if using monitoring)

Continuous Deployment

Vercel automatically redeploys when you push to your main branch:

git add .
git commit -m "Update feature"
git push origin main

Vercel will:

  1. Detect the push
  2. Start new build
  3. Run tests (if configured)
  4. Deploy automatically
  5. Notify you of status

Preview deployments are created for pull requests automatically.

Troubleshooting

Build Fails

Check:

  • Build logs in Vercel dashboard
  • All dependencies in package.json
  • TypeScript errors locally
  • Environment variables set correctly

Common issues:

  • Missing environment variables
  • TypeScript errors
  • Dependency conflicts

Authentication Not Working

Verify:

  • BETTER_AUTH_SECRET is set and different from dev
  • BETTER_AUTH_URL matches your actual URL
  • Convex environment variables match
  • Cookies are not blocked (HTTPS required)

Emails Not Sending

Check:

  • RESEND_API_KEY is production key
  • Domain is verified in Resend
  • EMAIL_FROM uses verified domain
  • DNS records are configured
  • Check Resend logs

Passkeys Not Working

Ensure:

  • Using HTTPS (not HTTP)
  • PASSKEY_RP_ID matches domain
  • Domain doesn't have port number
  • Browser supports WebAuthn

Database Connection Issues

Verify:

  • Convex deployment is active
  • All three Convex URLs are correct
  • Convex environment variables set
  • Check Convex dashboard logs

Performance Optimization

Optimize Images

Next.js automatically optimizes images. Use the Image component:

import Image from 'next/image';

<Image
  src="/logo.png"
  alt="Logo"
  width={200}
  height={200}
/>

Security Best Practices

  1. HTTPS Only: Never use HTTP in production
  2. Strong Secrets: Generate with openssl rand -base64 32
  3. Different Secrets: Dev and prod must be different
  4. Environment Variables: Never commit to git
  5. CORS: Configure appropriately for your domain
  6. Rate Limiting: Consider adding rate limiting
  7. Security Headers: Vercel sets these by default
  8. Regular Updates: Keep dependencies updated

Scaling

Unstack Pro scales automatically on Vercel and Convex:

  • Serverless Functions: Auto-scale with traffic
  • Convex: Scales automatically
  • No Infrastructure: Fully managed

Backup Strategy

Database Backups

Convex automatically backs up your data. To export:

  1. Go to Convex dashboard
  2. Settings → Export
  3. Download backup

Code Backups

Your code is already backed up in GitHub. Ensure:

  • Regular commits
  • Protected main branch
  • Pull request reviews
  • Tagged releases

Monitoring

Vercel Analytics

Enable in Vercel dashboard for:

  • Page views
  • Performance metrics
  • User analytics

Convex Logs

Monitor in Convex dashboard:

  • Function calls
  • Error rates
  • Performance
  • Data changes

Sentry (Optional)

For error tracking:

  • Catches runtime errors
  • Tracks error trends
  • User impact analysis
  • Source maps for debugging

Support

If issues persist:

  1. Check Vercel Docs
  2. Check Convex Docs
  3. Check better-convex Docs - Our Better Auth + Convex integration
  4. Check Better Auth Docs
  5. Review GitHub issues
  6. Contact support

Next Steps

After deployment:

  • Test all features thoroughly
  • Set up monitoring
  • Configure backup schedule
  • Plan for scaling
  • Document custom changes
  • Train team on admin panel
  • Set up staging environment (optional)

Consider setting up a staging environment that mirrors production for testing changes before they go live.

On this page