Go to Vercel Dashboard → Your Project → Settings → Environment Variables
Required variables for Production:
NEXTAUTH_URL = https://your-actual-domain.vercel.app
NEXTAUTH_SECRET = efgh
JWT_SECRET = abcd
DATABASE_URL = postgresql://...
UPLOADTHING_TOKEN = eyJhcGlLZXkiOi...
Common Mistakes:
- ❌
NEXTAUTH_URL = http://localhost:3000(wrong!) - ❌
NEXTAUTH_URL = your-actual-domain.vercel.app(missing https://) - ❌ Environment variable set to "Preview" only, not "Production"
- ❌ Variable name has typo (e.g.,
NEXT_AUTH_URLinstead ofNEXTAUTH_URL)
Your NEXTAUTH_URL must exactly match the domain you're visiting:
- If visiting
https://tarah.vercel.app→NEXTAUTH_URL=https://tarah.vercel.app - If visiting
https://www.yoursite.com→NEXTAUTH_URL=https://www.yoursite.com - If visiting
https://yoursite.com→NEXTAUTH_URL=https://yoursite.com
After adding/changing environment variables:
- Go to Deployments tab
- Click ⋯ (three dots) on latest deployment
- Click Redeploy
- Check "Use existing Build Cache" is unchecked
- Click Redeploy
- Go to your deployment in Vercel
- Click on the deployment
- Go to Runtime Logs tab
- Look for these log entries:
If you see the token logs, NextAuth is working
JWT Token: { ... role: 'CUSTOMER' ... }
- Open your production site
- Sign in
- Open DevTools (F12) → Console
- Look for errors like:
- "CSRF token mismatch"
- "No session found"
- Any red errors related to auth
- Open DevTools (F12) → Application tab → Cookies
- Look for
next-auth.session-token - Check:
- ✅ Cookie exists after login
- ✅ Has
Secureflag (should be checked in production) - ✅ Has
HttpOnlyflag - ✅
SameSite= Lax - ✅ Domain matches your site
If the profile redirects to sign-in, 99% of the time it's because:
NEXTAUTH_URL is missing or incorrect in Vercel
- Go to Vercel → Settings → Environment Variables
- Find
NEXTAUTH_URL - Click Edit
- Make sure the value is:
https://your-actual-domain.vercel.app - Make sure Production is checked ✓
- Click Save
- Go to Deployments → Redeploy
After redeploying:
- Clear browser cache and cookies for your production site
- Open production site in Incognito/Private window
- Sign up with a new email
- After signup, check URL - should be on
/not/sign-in - Navigate to
/profile - ✅ Should see profile page, NOT redirect
// Check if session exists
fetch('/api/auth/session')
.then(r => r.json())
.then(console.log)
// Check cookies
console.log(document.cookie)Expected output after login:
{
"user": {
"id": "...",
"email": "...",
"role": "CUSTOMER"
},
"expires": "..."
}If you get {}: Session is not being created = Environment variable issue
Send these screenshots if issue persists:
- Vercel Environment Variables page (blur sensitive values)
- Browser DevTools → Application → Cookies
- Browser DevTools → Console (after sign in)
- Vercel Runtime Logs during login
In Vercel CLI:
vercel --prodThis shows your production URL. Use this exact URL for NEXTAUTH_URL.