Bug report
Describe the bug
Local session is not updated after calling updateUser(). The session data remains the same.
To Reproduce
Steps to reproduce the behavior, please provide code snippets or a repository:
- Have some metadata to update, e.g.
posts.
updateUser({ data: { posts: count + 1 } }) after user successfully creates a new post.
- Read the user metadata with
useUser or reload the page.
- The count is not increased.
Expected behavior
Client-side session data and token should be updated to reflect the changes.
System information
- Version of supabase-js: 2.25.0
- Version of Node.js: 18.16.1
Additional context
After a PUT request to update the user, the retrieved session data is supposed to be saved locally with _saveSession(). That, in turn, hands it down to _persistSession(). During a debugger session, first two arguments to setItemAsync(this.storage, this.storageKey, currentSession) appear to be undefined. This could be the reason why the JWT remains outdated client-side.
It appears that the new session data is lost in stringifySupabaseSession(). As you can see, it only returns a select number of items, the rest is extracted from the current token. So when it's time to modify the session cookie, the new session data is mixed with the old one. As a result, most of the data modified in updateUser() is not recorded in the cookie. https://github.com/supabase/auth-helpers/blob/6e5b5b37dacd07ca74f7486419dda6b10bf14730/packages/shared/src/utils/cookies.ts#L69
Bug report
Describe the bug
Local session is not updated after calling
updateUser(). The session data remains the same.To Reproduce
Steps to reproduce the behavior, please provide code snippets or a repository:
posts.updateUser({ data: { posts: count + 1 } })after user successfully creates a new post.useUseror reload the page.Expected behavior
Client-side session data and token should be updated to reflect the changes.
System information
Additional context
After a
PUTrequest to update the user, the retrieved session data is supposed to be saved locally with_saveSession(). That, in turn, hands it down to_persistSession(). During a debugger session, first two arguments tosetItemAsync(this.storage, this.storageKey, currentSession)appear to beundefined. This could be the reason why the JWT remains outdated client-side.It appears that the new session data is lost in
stringifySupabaseSession(). As you can see, it only returns a select number of items, the rest is extracted from the current token. So when it's time to modify the session cookie, the new session data is mixed with the old one. As a result, most of the data modified inupdateUser()is not recorded in the cookie. https://github.com/supabase/auth-helpers/blob/6e5b5b37dacd07ca74f7486419dda6b10bf14730/packages/shared/src/utils/cookies.ts#L69