Skip to content

feat: experimental testing for split session and user storage#32833

Closed
hf wants to merge 1 commit into
masterfrom
hf/test-split-session-user-storage
Closed

feat: experimental testing for split session and user storage#32833
hf wants to merge 1 commit into
masterfrom
hf/test-split-session-user-storage

Conversation

@hf

@hf hf commented Jan 16, 2025

Copy link
Copy Markdown
Contributor

Allows testing split session and user storage.

Steps to test:

cd <path-to-gotrue-js/auth-js>
npm run build

# then
cd packages/common
pnpm link <path-to-gotrue-js>

@vercel

vercel Bot commented Jan 16, 2025

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
design-system ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jan 16, 2025 2:54pm
docs ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jan 16, 2025 2:54pm
studio-staging ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jan 16, 2025 2:54pm
zone-www-dot-com ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jan 16, 2025 2:54pm
2 Skipped Deployments
Name Status Preview Comments Updated (UTC)
studio ⬜️ Ignored (Inspect) Visit Preview Jan 16, 2025 2:54pm
studio-self-hosted ⬜️ Ignored (Inspect) Visit Preview Jan 16, 2025 2:54pm

@supabase

supabase Bot commented Jan 16, 2025

Copy link
Copy Markdown

This pull request has been ignored for the connected project xguihxuzqibwxjnimxev because there are no changes detected in supabase directory. You can change this behaviour in Project Integrations Settings ↗︎.


Preview Branches by Supabase.
Learn more about Supabase Branching ↗︎.

hf added a commit to supabase/auth-js that referenced this pull request Jun 4, 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:

```typescript
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](supabase/supabase#32833) can be used
to test this PR before merging. Merging should be safe as this is opt-in
behavior for now.

---------

Co-authored-by: Cemal Kilic <cemalkilic96@gmail.com>
Co-authored-by: Cemal Kılıç <cemalkilic@users.noreply.github.com>
@hf hf closed this Aug 27, 2025
@hf hf deleted the hf/test-split-session-user-storage branch August 27, 2025 14:05
mandarini pushed a commit to supabase/supabase-js that referenced this pull request Oct 2, 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:

```typescript
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](supabase/supabase#32833) can be used
to test this PR before merging. Merging should be safe as this is opt-in
behavior for now.

---------

Co-authored-by: Cemal Kilic <cemalkilic96@gmail.com>
Co-authored-by: Cemal Kılıç <cemalkilic@users.noreply.github.com>
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