Before running the application, you need to update the .env file with your actual Supabase credentials:
- Replace
[YOUR-PASSWORD]in theDATABASE_URLwith your actual database password from Supabase - Add your Supabase API keys:
SUPABASE_ANON_KEY: Your project's anonymous keySUPABASE_SERVICE_KEY: Your project's service role key
The .env file includes three connection options:
-
Direct Connection (default): Best for persistent connections
DATABASE_URL=postgresql://postgres:[YOUR-PASSWORD]@db.nmriopbblradducblaoc.supabase.co:5432/postgres -
Transaction Pooler: Best for serverless functions
DATABASE_URL=postgres://postgres:[YOUR-PASSWORD]@db.nmriopbblradducblaoc.supabase.co:6543/postgres -
Session Pooler: For IPv4 networks
DATABASE_URL=postgres://postgres.nmriopbblradducblaoc:[YOUR-PASSWORD]@aws-0-us-east-2.pooler.supabase.com:5432/postgres
- Make sure your
.envfile is configured with the correct credentials - Run the server:
go run ./cmd/server
- Test the database connection:
curl http://localhost:8080/debug/db
The error you're experiencing with "email_address_invalid" is likely due to Supabase Auth configuration. By default, Supabase might be configured to:
- Block certain email domains (like example.com)
- Require email confirmation
To fix this:
- Go to your Supabase Dashboard → Authentication → Settings
- Check if "Email Confirmations" is enabled
- Check if there are any email domain restrictions
- You can also disable email confirmations for testing:
- Go to Authentication → Providers → Email
- Toggle off "Confirm email"
Alternatively, use a real email address instead of demo@example.com for testing.
The database client is now available in your handlers through sb.Database. Example usage:
// Execute a query
rows, err := sb.Database.ExecuteQuery(ctx, "SELECT * FROM users WHERE email = $1", email)
// Execute a single row query
var userID string
err := sb.Database.ExecuteQueryRow(ctx, "SELECT id FROM users WHERE email = $1", email).Scan(&userID)- Never commit your
.envfile (it's already in .gitignore) - Keep your service role key secret
- Use environment variables in production
- Remove the
/debug/dbendpoint before deploying to production