supabase / auth-js

An isomorphic Javascript library for Supabase Auth.
MIT License
319 stars 152 forks source link

fix: `getUser` returns null if there is no session #876

Closed hf closed 2 months ago

hf commented 2 months ago

If there is no session (i.e. no JWT/access token), getUser() cannot possibly work. It now returns null user.

Previously, it just sent out a request without the JWT. When combined with @supabase/supabase-js which does some clever tricks with fetch by adding a default Authorization header using the Supabase anon API key, if you called getUser() at the wrong time an error such as missing sub claim error message would be thrown by Supabase Auth.

(Unfortunately the Supabase anon API key is signed with the same JWT secret, so it's hard to disambiguate why this is happening.)