Skip to content

fix: fall back to memory when browser storage access is denied - #305

Open
ItsM0rty wants to merge 1 commit into
supabase:mainfrom
ItsM0rty:fix/browser-user-storage-access
Open

ItsM0rty wants to merge 1 commit into
supabase:mainfrom
ItsM0rty:fix/browser-user-storage-access

Conversation

@ItsM0rty

Copy link
Copy Markdown

With cookies: { encode: "tokens-only" }, createBrowserClient() reads window.localStorage to choose where to store user data. That property can throw a SecurityError when browser policy blocks storage access. Client creation then fails before auth can use the cookie adapter.

This catches failures when obtaining the default browser storage and uses a fresh memory adapter instead, matching the existing non-browser fallback. Accessible localStorage is still used, and an explicit auth.userStorage takes precedence without touching localStorage. Tokens continue to use cookie storage. The option documentation explains that fallback user data lasts only for the lifetime of the client.

The regression uses a localStorage getter that throws a DOMException. It fails on the original implementation and passes with the fix. It also checks user storage read/write/removal, cookie-backed token storage, explicit userStorage, and the normal browser path.

All 123 tests pass across seven files. Both TypeScript builds, Prettier checks, and whitespace checks pass. This was tested in Node 22 with a simulated browser storage denial; a browser automation test was not run.

@ItsM0rty
ItsM0rty requested review from a team as code owners October 13, 2026 19:40

This branch has not been deployed

No deployments
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