📄 SKILL.md

← Vault

name: supabase-edge-runtime-401-debug

description: Debug 401 errors on Supabase Edge Runtime when all requests (authenticated or not) return 401 through Kong → functions-proxy → edge-runtime chain

triggers:

- "edge function returns 401 for all requests"

- "functions-proxy 401 even without Authorization header"

- "edge-runtime unresponsive through Kong proxy"

- "manage-users 401 Kong VPS"


Supabase Edge Runtime 401 Debugging Workflow

Problem Pattern

All requests to /functions/v1/ through Kong return 401, including:

Verification After Fix

`bash

Test from Kong

docker exec -it wget -O- -q 'http://127.0.0.1:8000/functions/v1/'

Test from outside (with token)

curl -s 'https://rochasalesseguros.com.br/functions/v1/' \

-H 'Authorization: Bearer ' \

-H 'apikey: '

`

Common Pitfalls

1. "No restart" constraint can be counterproductive. If edge-runtime is in a broken state, a simple docker restart often fixes it.

2. Container recreation resets code. If the functions container was recreated (check docker inspect --format '{{.Created}}'), any custom code in the volume is overwritten with the original. Re-apply fixes after container recreation.

3. Two code paths — edit the right one. The container mounts from /opt/rochasales/supabase/functions/, NOT /opt/rochasales/volumes/functions/. Always verify which path the container is actually reading from.

4. Admin panel working ≠ Edge Function working. The admin UI may work via Supabase REST API (/rest/v1/) while the Edge Function (/functions/v1/) still returns 401. These are separate auth paths.

5. Debug code not taking effect. If you modified the Edge Function and the response doesn't change, the runtime may be caching. Verify the code is actually in the container with docker exec cat /home/deno/functions//index.ts and restart the container.

Only pursue complex debugging (Option C without restart) if:

1. You have confirmed OTHER services on the VPS cannot tolerate the restart

2. You have exhausted the diagnostic steps above

3. You have verified the 401 is NOT coming from Kong's JWT plugin (no JWT plugins found in Kong config)