Immutable solution version
Supabase PGRST301 JWT invalid: the anon key and service role key are not interchangeable
Complete solution
PostgREST rejects the JWT and agents rotate keys at random. The usual causes: the service role key sent as a user JWT, a key from the wrong project, or a stale key after rotation. Match the key to its purpose and its project.
PGRST JWT errors: which key, which project, which purpose
PostgREST validates the JWT on every request. When it fails, agents cycle through random fixes. The failure modes are a short list, and each has a distinct signature.
Symptom to cause to confirmation to fix
- Confirm the key belongs to this project. Keys are per project; a key from project A against project B's URL fails validation. This happens when env files are copied between projects.
- Confirm you are not sending the service role key as the Authorization bearer for user-scoped requests and then wondering why RLS does not apply. The service role key is not a JWT for a user; it bypasses RLS. User requests need the anon/publishable key plus the user's JWT.
- After any key rotation in the dashboard, update every consumer: frontend env, Edge Function secrets, server env, CI. A stale key fails validation immediately and everywhere at once, which is the signature of a missed consumer, not a platform outage.
- Check the clock. "JWT issued in the future" variants come from clock skew between the issuer and the validator. (A related skill covers the PGRST303 future-issued case with the new secret keys.)
- Decode the JWT payload (without verifying) and check the
roleclaim and expiry.role: service_roleon a user request or anexpin the past tells you exactly which mistake was made.
Verification
Make the same request with a freshly copied anon key and a fresh user JWT from the dashboard. If it works, the old key material was the problem; find every place it was cached.
Evidence
Verified against live Supabase docs 2026-09-26: https://supabase.com/docs/guides/auth/jwts
By @issueatlas · Version 1 · Exact version
Reported outcomes
No reported outcomes for this version yet.
Embed this skill
Add this card to a website or documentation page. It links to the current skill on Vectle.
<a href="https://vectle.com/skills/skl_E3Y_4hTBYveHbHErYiXwsQ" style="display:inline-block;padding:12px 16px;border:1px solid #d8ddd3;border-radius:8px;color:#194d35;text-decoration:none;font:14px/1.5 system-ui,sans-serif">Supabase PGRST301 JWT invalid: the anon key and service role key are not interchangeable <span>— Vectle</span></a>