4.5 KiB
Deploy Edge Functions to Supabase
Problem
The Flutter app is getting "HTTP 401: Invalid JWT" because the Edge Functions either:
- Haven't been deployed yet, OR
- Are deployed but don't have environment variables set
Prerequisites
1. Install Supabase CLI
Option A: npm (if you have Node.js)
npm install -g supabase
Option B: Chocolatey (Windows)
choco install supabase
Option C: Direct download https://github.com/supabase/cli/releases
2. Login to Supabase CLI
supabase login
This will open a browser to generate an access token.
Deployment Steps
Step 1: Link Project
cd c:\Webs\Sojorn
supabase link --project-ref zwkihedetedlatyvplyz
Enter your database password when prompted.
Step 2: Deploy All Functions
# Deploy all Edge Functions at once
supabase functions deploy signup
supabase functions deploy profile
supabase functions deploy publish-post
supabase functions deploy publish-comment
supabase functions deploy appreciate
supabase functions deploy save
supabase functions deploy follow
supabase functions deploy block
supabase functions deploy report
supabase functions deploy feed-personal
supabase functions deploy feed-sojorn
supabase functions deploy trending
supabase functions deploy calculate-harmony
Or deploy all at once:
for func in signup profile publish-post publish-comment appreciate save follow block report feed-personal feed-sojorn trending calculate-harmony; do
supabase functions deploy $func --no-verify-jwt
done
Step 3: Set Environment Variables (Critical!)
The Edge Functions need these environment variables:
# Get your service role key from:
# https://app.supabase.com/project/zwkihedetedlatyvplyz/settings/api
supabase secrets set \
SUPABASE_URL=https://zwkihedetedlatyvplyz.supabase.co \
SUPABASE_ANON_KEY=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJzdXBhYmFzZSIsInJlZiI6Inp3a2loZWRldGVkbGF0eXZwbHl6Iiwicm9sZSI6ImFub24iLCJpYXQiOjE3Njc2Nzk3OTUsImV4cCI6MjA4MzI1NTc5NX0.7YyYOABjm7cpKa1DiefkI9bH8r6SICJ89nDK9sgUa0M \
SUPABASE_SERVICE_ROLE_KEY=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJzdXBhYmFzZSIsInJlZiI6Inp3a2loZWRldGVkbGF0eXZwbHl6Iiwicm9sZSI6InNlcnZpY2Vfcm9sZSIsImlhdCI6MTc2NzY3OTc5NSwiZXhwIjoyMDgzMjU1Nzk1fQ.nfXAU7m5v5PyaMJSEnwOjXxKnTiwpOWM_apIh91Rtfo
Step 4: Verify Deployment
# List deployed functions
supabase functions list
# Test a function
curl -i --location --request GET 'https://zwkihedetedlatyvplyz.supabase.co/functions/v1/feed-sojorn?limit=10' \
--header 'Authorization: Bearer YOUR_USER_JWT' \
--header 'apikey: eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJzdXBhYmFzZSIsInJlZiI6Inp3a2loZWRldGVkbGF0eXZwbHl6Iiwicm9sZSI6ImFub24iLCJpYXQiOjE3Njc2Nzk3OTUsImV4cCI6MjA4MzI1NTc5NX0.7YyYOABjm7cpKa1DiefkI9bH8r6SICJ89nDK9sgUa0M'
Alternative: Deploy via Supabase Dashboard
If CLI doesn't work, you can deploy manually:
- Go to: https://app.supabase.com/project/zwkihedetedlatyvplyz/functions
- Click "Create a new function"
- For each function:
- Name:
signup(etc.) - Copy code from
supabase/functions/signup/index.ts - Click "Deploy"
- Name:
- Set environment variables:
- Go to Settings > Edge Functions > Environment Variables
- Add:
SUPABASE_URL,SUPABASE_ANON_KEY,SUPABASE_SERVICE_ROLE_KEY
Troubleshooting
Error: "supabase: command not found"
Install Supabase CLI (see Prerequisites above)
Error: "Failed to deploy function"
Check that:
- You're logged in:
supabase login - Project is linked:
supabase link --project-ref zwkihedetedlatyvplyz - You have permissions on the project
Error: "Missing SUPABASE_URL"
Run Step 3 to set environment variables
Functions deployed but still getting 401
- Check environment variables are set:
supabase secrets list - Make sure secrets match
.envfile - Try redeploying after setting secrets
Quick Check: Are Functions Deployed?
Visit these URLs in your browser (should show CORS error, not 404):
- https://zwkihedetedlatyvplyz.supabase.co/functions/v1/feed-sojorn
- https://zwkihedetedlatyvplyz.supabase.co/functions/v1/profile
If you get 404: Functions not deployed If you get CORS or auth error: Functions deployed (good!) If you get JSON error response: Functions deployed and working!
After Deployment
- Restart Flutter app
- Try signing in
- JWT errors should be gone
The "Invalid JWT" error should change to a more specific error (or success!) once functions are deployed with correct environment variables.