Troubleshooting Guide
Auth loops, embedding failures, Stripe mismatches, and the env typos we see when someone clones fresh on a new laptop.
Authentication Issues
"Unauthorized" on Dashboard
Symptoms: Redirected to login, 401 errors
Solutions:
- Check Supabase URL and keys in
.env.local - Clear browser cookies and re-login
- Verify RLS policies are correct
- Check session hasn't expired
OAuth Login Fails
Symptoms: Error after OAuth redirect
Solutions:
- Verify callback URL in Supabase matches:
https://xxxxx.supabase.co/auth/v1/callback
- Check OAuth provider settings (client ID, secret)
- Enable the provider in Supabase Auth settings
- Verify redirect URLs in OAuth app settings
Profile Not Created
Symptoms: User logged in but no profile
Solutions:
- Check trigger function exists:
SELECT * FROM pg_trigger WHERE tgname = 'on_auth_user_created'; - Run trigger creation SQL from
schema.sql - Manually insert profile for testing
Chat Issues
"Insufficient Credits" (402)
Symptoms: Can't send messages
Solutions:
- Check profile credits in Supabase
- Add credits manually for testing:
UPDATE profiles SET credits = 100 WHERE id = 'user-id'; - Verify credit calculation in
credit-calculator.ts
Chat Messages Not Saving
Symptoms: Messages disappear on refresh
Solutions:
- Check RLS policies for messages table
- Verify chat_id is being passed correctly
- Check Supabase logs for insert errors
- Ensure user owns the chat
Streaming Not Working
Symptoms: Response appears all at once
Solutions:
- Check browser supports ReadableStream
- Verify
toTextStreamResponse()is used - Check for proxy/CDN buffering issues
- Try disabling response compression
Model Not Available
Symptoms: 403 on model selection
Solutions:
- Check user tier allows model
- Verify
pricing.tsincludes model in tier - Update tier in database if needed
RAG Issues
Document Upload Fails
Symptoms: Upload errors, timeout
Solutions:
- Check file size (max 10MB)
- Verify MIME type is allowed
- Check Supabase Storage bucket exists
- Verify storage policies allow upload
- Check user folder path format
No RAG Results
Symptoms: AI ignores uploaded documents
Solutions:
- Check document status is "completed"
- Verify embeddings exist:
SELECT COUNT(*) FROM document_embeddings WHERE document_id = 'doc-id'; - Check similarity threshold isn't too high
- Verify
documentIdsare passed to API - Test with lower
matchThreshold
Poor RAG Quality
Symptoms: Irrelevant or incomplete answers
Solutions:
- Increase
defaultTopKfor more context - Adjust chunk size/overlap in config
- Improve document formatting (clear headings)
- Check embedding model is working
- Review system prompt template
Stripe Issues
Webhook Not Received
Symptoms: Payment succeeds but tier not updated
Solutions:
- Check webhook endpoint URL is correct
- Verify webhook signing secret
- Check Stripe Dashboard → Webhooks → Logs
- Test locally with Stripe CLI:
stripe listen --forward-to localhost:3000/api/webhooks/stripe
Webhook Signature Error
Symptoms: 400 error on webhook
Solutions:
- Use
req.text()notreq.json():const body = await req.text(); // Correct - Verify
STRIPE_WEBHOOK_SECRETis correct - Check for whitespace in environment variable
Checkout Redirect Fails
Symptoms: Stuck on checkout or error
Solutions:
- Verify
NEXT_PUBLIC_APP_URLis correct - Check price ID exists and is active
- Verify Stripe API key is valid
- Check browser console for errors
Database Issues
RLS Policy Errors
Symptoms: Permission denied errors
Solutions:
- Verify policies exist:
SELECT * FROM pg_policies WHERE tablename = 'profiles'; - Re-run policy creation from
schema.sql - Check
auth.uid()returns correct user ID
pgvector Errors
Symptoms: Embedding queries fail
Solutions:
- Enable extension:
CREATE EXTENSION IF NOT EXISTS vector; - Verify embedding dimension matches (1536)
- Check index exists on embeddings column
- Rebuild index if corrupted
Connection Errors
Symptoms: "Connection terminated" errors
Solutions:
- Enable connection pooling in Supabase
- Reduce concurrent connections
- Check for connection leaks in code
- Verify database isn't paused (free tier)
Performance Issues
Slow Page Loads
Solutions:
- Check for N+1 query patterns
- Use parallel data fetching
- Add React Suspense boundaries
- Enable static generation where possible
High Token Usage
Solutions:
- Reduce
maxTokensfor responses - Limit conversation history length
- Use cheaper models for simple tasks
- Implement token-aware truncation
Memory Issues
Solutions:
- Reduce chunk batch size for embeddings
- Stream large file processing
- Limit concurrent document processing
- Add pagination for large data sets
Development Issues
TypeScript Errors
Solutions:
- Run
pnpm tsc --noEmitto check - Update types in
types/index.d.ts - Ensure config types are exported correctly
- Check for missing dependencies
Build Failures
Solutions:
- Check all environment variables are set
- Verify Stripe client has fallback for build time
- Run
pnpm buildlocally first - Check for import cycles
Hot Reload Not Working
Solutions:
- Restart dev server
- Clear
.nextfolder - Check for file system case sensitivity issues
- Verify Turbopack is working
Getting Help
If issues persist:
- Check console logs (browser and server)
- Review Supabase logs
- Check Stripe webhook logs
- Search existing GitHub issues
- Create detailed bug report with:
- Steps to reproduce
- Expected vs actual behavior
- Environment details
- Relevant logs