Overview
Cajas requires specific environment variables to connect to your Supabase backend. This guide walks you through setting up your.env.local file with the necessary configuration.
Required Environment Variables
The application needs two essential Supabase environment variables:| Variable | Description | Where to Find |
|---|---|---|
NEXT_PUBLIC_SUPABASE_URL | Your Supabase project URL | Project Settings > API |
NEXT_PUBLIC_SUPABASE_ANON_KEY | Public anon/client key | Project Settings > API |
Setup Instructions
Create Environment File
Create a
.env.local file in the root of your project:The
.env.local file is automatically ignored by git (see .gitignore). Never commit sensitive credentials to version control.Add Supabase Credentials
Open Replace the placeholder values with your actual Supabase project details.
.env.local and add your Supabase project credentials:.env.local
Verify Configuration
The environment variables are used in two key files:Client-side usage (Server-side usage (
lib/supabase/client.ts:5-6):lib/supabase/server.ts:8-9):Environment Files Guide
Cajas follows Next.js environment variable conventions:.env.local- Local development (gitignored).env.production- Production environment.env.example- Template for required variables (committed to git)
Troubleshooting
”Invalid API key” Error
Check your anon key
Check your anon key
Ensure you’re using the anon (public) key, not the service role key. The service role key should never be exposed to the client.Find it in: Supabase Dashboard > Project Settings > API >
anon publicVerify URL format
Verify URL format
The URL should follow this format:Do not include trailing slashes or additional paths.
Restart required
Restart required
Environment variables are loaded at build time. You must restart your development server after changing
.env.local:Environment Variables Not Loading
Check file location
Check file location
Ensure
.env.local is in the project root directory, at the same level as package.json.Verify syntax
Verify syntax
Environment variables should not have quotes or spaces:
Clear Next.js cache
Clear Next.js cache
Sometimes Next.js caches environment variables. Clear the cache and restart:
Security Best Practices
Never Commit Secrets
Always add
.env.local to .gitignore. The project is already configured to ignore .env* files.Use Anon Key Only
Only use the public
anon key in NEXT_PUBLIC_ variables. The service role key should only be used server-side.Rotate Keys Regularly
Rotate your API keys periodically and immediately if they’re ever exposed.
Environment-Specific Values
Use different Supabase projects for development, staging, and production environments.
Next Steps
Supabase Configuration
Set up your Supabase project and enable required services
Database Migrations
Run database migrations to set up your schema
