Skip to content

feat: introduce experimental split user and session storage #1023

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Jun 4, 2025

Conversation

hf
Copy link
Contributor

@hf hf commented Jan 16, 2025

A common complaint when using Supabase in SSR is that the cookie size is huge. Some server configurations are not able to use such large cookies.

A major contributor to cookie size is that the user object is stored alongside the access and refresh tokens. This object should not be used on the server but nevertheless has to exist to make this library happy.

This change introduces the ability for this library to store the user object in a separate storage location. For now it's experimental mode to be proofed before being widely adopted.

How does it work?

You can initialize the client by passing in a new option userStorage in addition to the already existing and optional storage option. By default userStorage is not set and a single storage is used for all elements of the session (including user property).

If userStorage is set, all future changes to the session will write the user there, and the rest of the session object to storage.

Unsolvable Problems

Say you set up the client like so:

new GoTrueClient(URL, {
  // ...
  storage: cookieStorage,
  userStorage: window.localStorage,
})

On the server, the cookies -- obviously -- will not contain the user object. Because the Session type defines user: User as non-nullable, attempting to access a property on this object will throw an exception. Instead you should always call getUser() to fetch a trusted and fresh user object. This problem will be solved in v3 of this library.

Testing

This PR can be used to test this PR before merging. Merging should be safe as this is opt-in behavior for now.

@hf hf force-pushed the hf/introduce-split-session-and-user-storage branch from 6d757c8 to a924a9d Compare January 16, 2025 15:04
@cemalkilic cemalkilic force-pushed the hf/introduce-split-session-and-user-storage branch from 34fcef0 to 33848e3 Compare June 3, 2025 12:55
@hf hf merged commit e7b2f21 into master Jun 4, 2025
6 of 7 checks passed
@hf hf deleted the hf/introduce-split-session-and-user-storage branch June 4, 2025 07:57
hf added a commit that referenced this pull request Jun 6, 2025
Due to bad typing the `null` case of a missing session when using the
`userStorage` option introduced in #1023 caused a crash.
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.

2 participants