Skip to content

feat: Supabase Anonymous Auth + JWT for chat endpoint - #2

Merged
WSlag merged 4 commits into
mainfrom
feature/supabase-anonymous-auth
Jul 17, 2026
Merged

WSlag merged 4 commits into
mainfrom
feature/supabase-anonymous-auth

Conversation

@WSlag

@WSlag WSlag commented Jul 17, 2026

Copy link
Copy Markdown
Owner

Summary

Replace shared-API-key + �dmin=True database access with Supabase Anonymous Auth + JWT.

Changes

  • api/auth.py - Added �erify_jwt() dependency (validates Bearer token via supabase.auth.get_user())
  • api/main.py - /chat requires JWT, removed user_id from request body, CORS uses configurable origin
  • api/chat_v2.py - user_id required param (no default), validation from JWT guarantee
  • api/apply.py - Client-side Supabase anonymous auth, sends JWT in Authorization header
  • 3 repositories - Switched from �dmin=True (service_role) to �dmin=False (anon key) for RLS enforcement
  • schema.sql + migration - RLS policies changed from current_setting('app.user_id') to �uth.uid()
  • Tests - 104/104 passing, new JWT auth test cases

How It Works

  1. User clicks "Chat with Sara" ? browser calls supabase.auth.sign_in_anonymously()
  2. Supabase returns a JWT ? browser stores it in localStorage
  3. Each chat request includes Authorization: Bearer
  4. Backend validates JWT, extracts user_id from sub claim
  5. Repositories use anon key ? RLS enforces per-user row access

WSlag added 4 commits July 17, 2026 00:15
- Add verify_jwt() dependency to api/auth.py — validates Bearer token via supabase.auth.get_user()
- Remove user_id from ChatRequest body, read from JWT sub claim instead
- Switch session/profile/conversation repositories to admin=False (anon key)
- Update RLS policies from current_setting('app.user_id') to auth.uid()
- Add CORS_ORIGIN config for website origin
- Rewrite auth tests for JWT flow (104 tests passing)
- Replace UUID-based user_id with Supabase anonymous auth
- Inject SUPABASE_URL and SUPABASE_ANON_KEY from server config
- Send Authorization: Bearer <jwt> header instead of user_id in body
- Auto-refresh session on 401 response
@WSlag
WSlag merged commit 0e15a25 into main Jul 17, 2026
0 of 2 checks passed
@WSlag
WSlag deleted the feature/supabase-anonymous-auth branch July 17, 2026 04:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant