Summary
Back-end ContextRetriever implementations validate every authenticated request with a remote call to Supabase (auth.retrieveUser(token)), putting a network round-trip on the hot path of essentially every API call. We should verify the Supabase JWT locally (signature + exp/iss/aud) and only fall back to a remote lookup when strictly necessary.
Tracks Plan 4 from the back-end auth reassessment: edifikana/docs/04-local-jwt-verification.md (see also edifikana/docs/README.md).
Problem
- Latency: every request pays a round-trip to the auth provider before any business logic runs.
- Coupling to provider availability: a Supabase slowdown/outage degrades all authenticated traffic.
- Cost/throughput: ties request throughput to the auth provider's rate limits.
Affects SupabaseContextRetriever (edifikana) and FlyerBoardContextRetriever (flyerboard), which both call auth.retrieveUser per request.
Proposal
Verify the signed Supabase JWT locally using the project's JWT secret / JWKS:
- Validate signature,
exp, iss, aud without a network call.
- Build the context payload from token claims (
sub -> user id, etc.).
- Reserve
auth.retrieveUser (or a short-TTL cached variant) for cases that genuinely need freshly-fetched user data not present in the token.
Verification options
- Symmetric (HS256) secret — validate with the Supabase JWT secret. Simplest; requires securely provisioning the secret.
- Asymmetric (JWKS) — fetch and cache the JWKS and verify against rotating public keys. More robust to key rotation; avoids shipping a shared secret.
Acceptance criteria
Risks / notes
- Secret management: the JWT secret is sensitive; JWKS avoids a shared secret.
- Claim drift: pin expected claim names; cover with tests.
- Revocation: local verification cannot see server-side revocation before
exp; keep a lightweight cached remote check for sensitive ops if immediate revocation matters.
Full plan: edifikana/docs/04-local-jwt-verification.md
Summary
Back-end
ContextRetrieverimplementations validate every authenticated request with a remote call to Supabase (auth.retrieveUser(token)), putting a network round-trip on the hot path of essentially every API call. We should verify the Supabase JWT locally (signature +exp/iss/aud) and only fall back to a remote lookup when strictly necessary.Tracks Plan 4 from the back-end auth reassessment:
edifikana/docs/04-local-jwt-verification.md(see alsoedifikana/docs/README.md).Problem
Affects
SupabaseContextRetriever(edifikana) andFlyerBoardContextRetriever(flyerboard), which both callauth.retrieveUserper request.Proposal
Verify the signed Supabase JWT locally using the project's JWT secret / JWKS:
exp,iss,audwithout a network call.sub-> user id, etc.).auth.retrieveUser(or a short-TTL cached variant) for cases that genuinely need freshly-fetched user data not present in the token.Verification options
Acceptance criteria
config.properties.*/SettingsHolder), never hard-coded.Risks / notes
exp; keep a lightweight cached remote check for sensitive ops if immediate revocation matters.Full plan:
edifikana/docs/04-local-jwt-verification.md