sojorn/sojorn_docs/archive/DEPLOY_EDGE_FUNCTIONS.md
Patrick Britton 38653f5854 Sojorn Backend Finalization & Cleanup - Complete Migration from Supabase
##  Phase 1: Critical Feature Completion (Beacon Voting)
- Add VouchBeacon, ReportBeacon, RemoveBeaconVote methods to PostRepository
- Implement beacon voting HTTP handlers with confidence score calculations
- Register new beacon routes: /beacons/:id/vouch, /beacons/:id/report, /beacons/:id/vouch (DELETE)
- Auto-flag beacons at 5+ reports, confidence scoring (0.5 base + 0.1 per vouch)

##  Phase 2: Feed Logic & Post Distribution Integrity
- Verify unified feed logic supports all content types (Standard, Quips, Beacons)
- Ensure proper distribution: Profile Feed + Main/Home Feed for followers
- Beacon Map integration for location-based content
- Video content filtering for Quips feed

##  Phase 3: The Notification System
- Create comprehensive NotificationService with FCM integration
- Add CreateNotification method to NotificationRepository
- Implement smart deep linking: beacon_map, quip_feed, main_feed
- Trigger notifications for beacon interactions and cross-post comments
- Push notification logic with proper content type detection

##  Phase 4: The Great Supabase Purge
- Delete function_proxy.go and remove /functions/:name route
- Remove SupabaseURL, SupabaseKey from config.go
- Remove SupabaseID field from User model
- Clean all Supabase imports and dependencies
- Sanitize codebase of legacy Supabase references

##  Phase 5: Flutter Frontend Integration
- Implement vouchBeacon(), reportBeacon(), removeBeaconVote() in ApiService
- Replace TODO delay in video_comments_sheet.dart with actual publishComment call
- Fix compilation errors (named parameters, orphaned child properties)
- Complete frontend integration with Go API endpoints

##  Additional Improvements
- Fix compilation errors in threaded_comment_widget.dart (orphaned child property)
- Update video_comments_sheet.dart to use proper named parameters
- Comprehensive error handling and validation
- Production-ready notification system with deep linking

##  Migration Status: 100% Complete
- Backend: Fully migrated from Supabase to custom Go/Gin API
- Frontend: Integrated with new Go endpoints
- Notifications: Complete FCM integration with smart routing
- Database: Clean of all Supabase dependencies
- Features: All functionality preserved and enhanced

Ready for VPS deployment and production testing!
2026-01-30 09:24:31 -06:00

4.5 KiB

Deploy Edge Functions to Supabase

Problem

The Flutter app is getting "HTTP 401: Invalid JWT" because the Edge Functions either:

  1. Haven't been deployed yet, OR
  2. 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

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:

  1. Go to: https://app.supabase.com/project/zwkihedetedlatyvplyz/functions
  2. Click "Create a new function"
  3. For each function:
    • Name: signup (etc.)
    • Copy code from supabase/functions/signup/index.ts
    • Click "Deploy"
  4. 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:

  1. You're logged in: supabase login
  2. Project is linked: supabase link --project-ref zwkihedetedlatyvplyz
  3. You have permissions on the project

Error: "Missing SUPABASE_URL"

Run Step 3 to set environment variables

Functions deployed but still getting 401

  1. Check environment variables are set:
    supabase secrets list
    
  2. Make sure secrets match .env file
  3. Try redeploying after setting secrets

Quick Check: Are Functions Deployed?

Visit these URLs in your browser (should show CORS error, not 404):

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

  1. Restart Flutter app
  2. Try signing in
  3. 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.