📄 SKILL.md

← Vault

name: supabase-auth-flow-nginx-debug

description: Debug Supabase auth login flash-loops by reading nginx access logs to trace the exact API sequence the browser uses, identifying which POST-login verification check fails and causes the 204 logout.


Supabase Auth Flow Debug via Nginx Logs

Debug why a Supabase-based frontend app logs out immediately after successful login.

The Problem

Frontend login appears to succeed (auth returns 200) but browser immediately gets logged out (204 on logout endpoint). The user sees a "flash" of logged-in state then returns to login page.

Root Cause Pattern

The frontend does post-login verification checks before confirming the session:

1. Login succeeds (200)

2. Frontend calls GET /rest/v1/profiles?is_active=eq.true → if 400, logout

3. Frontend calls GET /rest/v1/user_roles?user_id=eq.{id}&role=eq.admin → if 400, logout

4. Frontend calls GET /rest/v1/custom_roles?has_admin_access=eq.true → if 400, logout

If ANY of these fail with 400, the frontend calls POST /logout immediately.

Diagnosis Technique

Step 1: Identify the exact API sequence the browser makes

Read the nginx access log on the VPS (not the auth container log):

`bash

sshpass -p '$PASS' ssh root@$VPS_IP \

"tail -200 /var/log/nginx/access.log | grep -E '(custom_roles|user_roles|profiles|logout|token)'"

`

Look for the pattern:

Quick Fix Checklist

`bash

1. Grant auth schema permissions

docker exec deploy-vps-db-1 psql -U postgres -d postgres -c \

"GRANT USAGE ON SCHEMA auth TO authenticated; GRANT ALL ON ALL TABLES IN SCHEMA auth TO authenticated;"

2. Ensure RLS policies allow authenticated SELECT

docker exec deploy-vps-db-1 psql -U postgres -d postgres -c \

"DROP POLICY IF EXISTS user_roles_select ON user_roles; \

CREATE POLICY user_roles_select ON user_roles FOR SELECT TO authenticated USING (true) WITH CHECK (true);"

3. Add missing columns

docker exec deploy-vps-db-1 psql -U postgres -d postgres -c \

"ALTER TABLE custom_roles ADD COLUMN IF NOT EXISTS has_admin_access BOOLEAN DEFAULT false;"

4. Reload PostgREST schema

docker exec deploy-vps-rest-1 kong reload

`

Verification

After fixes, confirm all endpoints work with curl:

`bash

TOKEN="..." # from auth logs

ANON_KEY="..."

curl -s "https://domain.com/rest/v1/profiles?select=id,user_id,is_active" \

-H "Authorization: Bearer $TOKEN" -H "apikey: $ANON_KEY"

curl -s "https://domain.com/rest/v1/user_roles?select=role&user_id=eq.{uuid}" \

-H "Authorization: Bearer $TOKEN" -H "apikey: $ANON_KEY"

curl -s "https://domain.com/rest/v1/custom_roles?select=id,name,has_admin_access" \

-H "Authorization: Bearer $TOKEN" -H "apikey: $ANON_KEY"

`

All should return 200 with data, not 400.