supabase-js
supabase-js copied to clipboard
fix(auth): clear local storage on signOut when session is already missing
Summary
Fixes signOut throwing AuthSessionMissingError and leaving stale session data in local storage when the session was already invalidated from another device.
Problem
When a user signs out globally from one device, all sessions are invalidated on the server. If the user then tries to call signOut() from a second device, the method throws AuthSessionMissingError and returns early without clearing the local storage. This leaves the client in a broken state with stale session data.
Solution
Handle AuthSessionMissingError in _signOut by:
- Not returning early when sessionError is AuthSessionMissingError
- Ignoring AuthSessionMissingError from admin.signOut alongside existing 404/401/403 handling
This ensures local storage is always cleared when signOut is called, regardless of server-side session state.
Related
Closes https://github.com/supabase/supabase-js/issues/1616