feat: introduce experimental split user and session storage #1023
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 optionalstorage
option. By defaultuserStorage
is not set and a single storage is used for all elements of the session (includinguser
property).If
userStorage
is set, all future changes to the session will write the user there, and the rest of the session object tostorage
.Unsolvable Problems
Say you set up the client like so:
On the server, the cookies -- obviously -- will not contain the
user
object. Because theSession
type definesuser: User
as non-nullable, attempting to access a property on this object will throw an exception. Instead you should always callgetUser()
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.