Skip to content

Latest commit

 

History

History
97 lines (71 loc) · 2.98 KB

File metadata and controls

97 lines (71 loc) · 2.98 KB

Database Connection Setup Guide

Quick Connection Test

Visit: http://localhost:3000/api/health

This will show you:

  • ✅ If environment variables are set correctly
  • ✅ If the database connection is working
  • ❌ Any specific errors preventing connection

Common Issues and Solutions

1. Missing Environment Variables

Error: "Missing Supabase environment variables"

Solution:

  1. Check that .env.local exists in the project root
  2. Ensure it contains:
    NEXT_PUBLIC_SUPABASE_URL=your_supabase_project_url
    NEXT_PUBLIC_SUPABASE_PUBLISHABLE_DEFAULT_KEY=your_supabase_publishable_key
    
  3. Restart your dev server after adding/changing environment variables

2. Database Tables Don't Exist

Error: "relation 'public.users' does not exist" or similar

Solution:

  1. Go to your Supabase Dashboard → SQL Editor
  2. Copy the contents of lib/supabase/migrations.sql
  3. Paste and run it in the SQL Editor
  4. This creates all necessary tables, indexes, and RLS policies

3. Wrong Environment Variable Names

Issue: You have DATABASE_URL and DIRECT_URL but the app needs:

  • NEXT_PUBLIC_SUPABASE_URL (not DATABASE_URL)
  • NEXT_PUBLIC_SUPABASE_PUBLISHABLE_DEFAULT_KEY (this is your anon/publishable key)

Solution:

  • NEXT_PUBLIC_SUPABASE_URL = Your Supabase project URL (found in Settings → API)
  • NEXT_PUBLIC_SUPABASE_PUBLISHABLE_DEFAULT_KEY = Your Supabase anon/publishable key (found in Settings → API)

Note: DATABASE_URL and DIRECT_URL are for direct PostgreSQL connections (like Prisma), not for the Supabase client library.

4. RLS (Row Level Security) Issues

Error: "new row violates row-level security policy"

Solution:

  • The migrations.sql file sets up RLS policies
  • Make sure you've run the complete migrations.sql file
  • Check in Supabase Dashboard → Authentication → Policies that policies exist

Step-by-Step Setup

  1. Get your Supabase credentials:

    • Go to https://supabase.com/dashboard
    • Select your project
    • Go to Settings → API
    • Copy:
      • Project URL → NEXT_PUBLIC_SUPABASE_URL
      • anon/public key → NEXT_PUBLIC_SUPABASE_PUBLISHABLE_DEFAULT_KEY
  2. Create .env.local file:

    NEXT_PUBLIC_SUPABASE_URL=https://your-project.supabase.co
    NEXT_PUBLIC_SUPABASE_PUBLISHABLE_DEFAULT_KEY=your-anon-key-here
  3. Run database migrations:

    • Go to Supabase Dashboard → SQL Editor
    • Copy contents of lib/supabase/migrations.sql
    • Paste and execute
  4. Test the connection:

    • Visit http://localhost:3000/api/health
    • Should show "Database connection successful"
  5. Restart your dev server:

    npm run dev

Verifying Your Setup

After setup, you should be able to:

  • ✅ Sign up new users
  • ✅ Sign in with email/password
  • ✅ Sign in with Google (if configured)
  • ✅ Create properties
  • ✅ Create and sign contracts

If any of these fail, check the browser console and the /api/health endpoint for specific error messages.