Overview
Galey Cloud requires environment variables for:- Supabase: Database and authentication
- Vercel Blob: Photo storage
- Development: Local development redirects
Required Environment Variables
Supabase Configuration
Your Supabase project URLFormat:
https://xxxxxxxxxxxxx.supabase.coWhere to find:- Go to Supabase Dashboard
- Select your project
- Navigate to Settings → API
- Copy Project URL
lib/supabase/client.ts:5lib/supabase/server.ts:13lib/supabase/middleware.ts:12
The
NEXT_PUBLIC_ prefix makes this variable accessible in browser code. This is safe because it’s a public URL.Your Supabase anonymous/public API keyFormat: Long JWT token starting with
eyJ...Where to find:- Go to Supabase Dashboard
- Select your project
- Navigate to Settings → API
- Copy Project API keys →
anonpublic
lib/supabase/client.ts:6lib/supabase/server.ts:14lib/supabase/middleware.ts:13
Vercel Blob Configuration
Vercel Blob storage access tokenWhere to find:
This is automatically added when you connect Vercel Blob to your project:
- Go to your Vercel project dashboard
- Navigate to Storage
- Create or connect a Blob store
- Click “Connect to Project”
- The token is automatically added to your environment variables
app/api/photos/upload/route.ts(via@vercel/blob)app/api/photos/delete/route.ts(via@vercel/blob)
The
@vercel/blob package automatically uses this environment variable. You don’t need to manually pass it to the SDK.Development-Only Variables
Custom redirect URL for development environmentDefault:
http://localhost:3000/auth/callbackWhere to use: Only needed if you’re using a different local development URLUsed in:app/auth/sign-up/page.tsx:44
This is only used during development. In production, Supabase uses the Site URL configured in your Supabase dashboard.
Environment Files
Local Development (.env.local)
Create a.env.local file in your project root for local development:
.env.local
Vercel Production Environment
In Vercel, configure environment variables through the dashboard:Navigate to environment variables
- Go to your Vercel project dashboard
- Click Settings → Environment Variables
Add each variable
For each variable:
- Enter Key (variable name)
- Enter Value (secret value)
- Select Environments:
- Production: Main branch deployments
- Preview: Branch and PR deployments
- Development: Local development with Vercel CLI
Development vs Production Configurations
Development Environment
Purpose: Local development and testing Configuration:- Use
.env.localfile - Connect to development Supabase project (optional)
- Use
http://localhost:3000for redirect URLs
- Use separate Supabase project for development
- Don’t use production credentials locally
- Test with realistic but non-sensitive data
Preview Environment
Purpose: Testing branches and pull requests Configuration:- Use same environment variables as production
- Automatic deployments for each PR
- Unique URLs for each deployment (e.g.,
your-app-git-feature.vercel.app)
- Use production Supabase project or a staging project
- Test authentication flows with preview URLs
- Add preview URLs to Supabase redirect whitelist
Production Environment
Purpose: Live application for end users Configuration:- All variables configured in Vercel dashboard
- Custom domain configured
- Production Supabase project
- Use strong, unique credentials
- Enable email confirmation in Supabase
- Monitor usage and set up alerts
- Regular security audits
Security Considerations
Public vs Private Variables
Variables withNEXT_PUBLIC_ prefix:
- Accessible in browser JavaScript
- Bundled into client-side code
- Should only contain non-sensitive values
NEXT_PUBLIC_ prefix:
- Only accessible on the server
- Never exposed to the browser
- Can contain sensitive secrets
In Galey Cloud, all Supabase variables use
NEXT_PUBLIC_ because they’re safe to expose:- The URL is publicly accessible
- The anon key is designed to be public
- Row-Level Security protects data access
Supabase Service Role Key
Only useservice_role key if:
- Running admin operations in a secure backend
- Using Supabase CLI for migrations
- Building internal tools that need unrestricted access
Blob Storage Token
BLOB_READ_WRITE_TOKEN is a server-side secret:
- Never exposed to the browser
- Only used in API routes (
/api/photos/upload,/api/photos/delete) - Grants read/write access to Vercel Blob storage
Best Practices
Rotate secrets regularly
- Rotate API keys every 3-6 months
- Immediately rotate if a key is exposed
- Update keys in both Supabase/Vercel and your environment variables
Use different projects per environment
- Development:
galey-dev.supabase.co - Staging:
galey-staging.supabase.co - Production:
galey-prod.supabase.co
Limit access to environment variables
- Only grant Vercel project access to necessary team members
- Use Vercel teams to control access
- Audit who has access to production secrets
Monitor for leaks
- Use tools like GitGuardian to scan commits
- Check public repositories for accidentally committed secrets
- Enable secret scanning on GitHub
Validation and Testing
Verify Environment Variables
Create a simple test page to verify variables are loaded (for development only):app/test-env/page.tsx
Test Supabase Connection
Verify Supabase credentials work:{"message":"Welcome to PostgREST"}
Test Blob Storage
In a Vercel deployment, check runtime logs when uploading a photo. You should see successful blob operations without authentication errors.Troubleshooting
”Supabase URL is required” error
Cause:NEXT_PUBLIC_SUPABASE_URL is not set
Solution:
- Verify the variable is set in
.env.local(development) or Vercel dashboard (production) - Restart development server:
npm run dev - Redeploy on Vercel if in production
”Invalid API key” error
Cause:NEXT_PUBLIC_SUPABASE_ANON_KEY is incorrect or malformed
Solution:
- Copy the key again from Supabase dashboard → Settings → API
- Ensure no extra spaces or quotes
- Verify you’re using the
anonkey, notservice_role
Blob upload fails with 401 Unauthorized
Cause:BLOB_READ_WRITE_TOKEN is missing or invalid
Solution:
- Verify Vercel Blob is connected to your project
- Check Settings → Environment Variables for
BLOB_READ_WRITE_TOKEN - Reconnect Blob storage if necessary
Environment variables not updating
Cause: Environment variables are cached or not reloaded Solution:- Local development: Restart dev server (
Ctrl+C, thennpm run dev) - Vercel: Trigger a new deployment (push to Git or use Deployments → Redeploy)
Variables work locally but not in Vercel
Cause: Variables not configured in Vercel dashboard Solution:- Go to Vercel project → Settings → Environment Variables
- Add missing variables
- Select correct environments (Production/Preview/Development)
- Redeploy
Reference Implementation
Here’s how environment variables are used throughout the codebase:Supabase Client (Browser)
lib/supabase/client.ts
Supabase Client (Server)
lib/supabase/server.ts
Vercel Blob Upload
app/api/photos/upload/route.ts
Next Steps
Supabase Setup
Configure your Supabase project
Vercel Deployment
Deploy to Vercel
Deployment Overview
Return to overview