Skip to content

user object warning logged, even when not touching session.user #1709

Closed

Description

@j4crev

Bug report

  • I confirm this is a bug with Supabase, not with my own application.
  • I confirm I have searched the Docs, GitHub Discussions, and Discord.

Describe the bug

With supabase-js@2.42.5 and the ssr auth helper package, after a user logs in, the below warning is logged to the server console five times, with a fairly minimal SvelteKit app. This happens despite the fact that none of my code is calling session.user, nor am I destructuring the user property from session, or destructuring with ...rest-type syntax.

Using the user object as returned from supabase.auth.getSession() or from some supabase.auth.onAuthStateChange() events could be insecure! This value comes directly from the storage medium (usually cookies on the server) and many not be authentic. Use supabase.auth.getUser() instead which authenticates the data by contacting the Supabase Auth server.

To Reproduce

Steps to reproduce the behavior, please provide code snippets or a repository:

https://github.com/j4w8n/getsession-warning

Expected behavior

The warning should not log when dev code doesn't explicitly call session.user.

Root Cause

I figured out why the first three logs happen: the Supabase client's server-side storage, from +layout.ts, is returning stringified JSON. You can see this in the docs. JSON.stringify() causes each property of session to be touched during the stringify process, which inevitably calls session.user. So, each time _useSession() is called, whether implicitly through dev code like getSession() or explicitly with internal auth-js processes, the warning is being logged.

I can't figure out where the final two warning logs are coming from. Could be from the same client initialization as above, but perhaps whatever triggers it is getting run asynchronously, so it's logging later.

Even if this warning wasn't an issue in the context of ssr, it could still be problematic, as the auth-js client itself calls session.user when updating a user, setting a session, refreshing a session, and more - at least some of which could theoretically happen server-side.

System information

  • OS: Windows, with or without WSL.
  • Browser N/A
  • Version of supabase-js: 2.42.5
  • Version of ssr: 0.3.0, but it should happen on earlier versions too I'd think.
  • Version of Node.js: N/A

Additional context

supabase/auth-js#873
supabase/auth-js#873 (comment)
https://tc39.es/ecma262/multipage/structured-data.html#sec-json.stringify
https://tc39.es/ecma262/multipage/structured-data.html#sec-serializejsonproperty
https://github.com/supabase/auth-js/blob/master/src/GoTrueClient.ts#L1111-L1124

Activity

  1. added
    bug
    on Apr 24, 2024
  2. j4crev commented on Apr 27, 2024

    @j4crev
    ContributorAuthor
  3. j4crev commented on Apr 28, 2024

    @j4crev
    ContributorAuthor

    It's likely the other two warnings, that I couldn't figure out how they are triggering, are triggered when SvelteKit checks if passed values are POJOs, in certain situations. See supabase/auth-js#873 (comment)

  4. kangmingtay commented on May 2, 2024

    @kangmingtay
    Member

    hey @j4w8n, we made another attempt in this PR to further cut down on the repeated warning logs returned - basically everytime we detect that a new session is saved, we set a flag to suppress the warning internally

  5. j4crev commented on May 2, 2024

    @j4crev
    ContributorAuthor

    Thanks @kangmingtay. I suspect that PR will resolve issues for some people - specifically the ones exclusively experiencing this when calling things like updateUser(). However, this has basically no effect for SvelteKit users - at least not on initial login and hard refreshes - because of the nature of what I explained in the first paragraph of the Root Cause section.

    As an aside, how do I test an RC? I added an override in my package.json, and after doing bun install it claimed it installed one thing. When I go to the auth-js package.json the version is 2.64.2-rc.1, but none of the code from the release is in there - I had to add it manually to test. I was looking in dist/main/GoTrueClient.js, but I even glanced at the .ts version in src and saw nothing. I had this experience with pnpm as well, in another demo app.

  6. j4crev commented on May 2, 2024

    @j4crev
    ContributorAuthor

    @kangmingtay looks like there is something wrong with the build process for RCs. If you checkout the code on npm, you'll see the PR code is not there.
    https://www.npmjs.com/package/@supabase/auth-js/v/2.64.2-rc.1?activeTab=code

  7. kangmingtay commented on May 3, 2024

    @kangmingtay
    Member

    @j4w8n ah good point, not sure why the release workflow got skipped in the first attempt but i reran it and it's published to npm so you should be able to test it out

  8. kangmingtay commented on May 3, 2024

    @kangmingtay
    Member

    @j4w8n yeah your analysis is right, any method that implicitly accesses the user property in the session object will trigger the warning log.

    i think we can implement your suggestion here so the warning is only logged once per proxy session, but will need some time to test this out since we're currently quite tight on bandwidth

  9. vehm commented on May 3, 2024

    @vehm

    Confirming that we are continuing to receive the warning in SvelteKit after #895 as mentioned here.

    Will follow.

  10. j4crev commented on May 3, 2024

    @j4crev
    ContributorAuthor

    Until this issue is resolved, and perhaps even after that, I've tweaked my demo app - v0.3.0 - to where I no longer receive any warnings.

    My solution is done in a legitimate way, which checks all of the security boxes. The code in hooks.server.ts verifies the JWT and uses it's decoded data to craft a validated session. This session will pass any internal auth-js checks, as well as type checks.

    https://github.com/j4w8n/sveltekit-supabase-ssr

  11. silentworks commented on May 7, 2024

    @silentworks
    Contributor

    I think the suggestion here from @j4w8n is great but I'd also like a way to suppress this warning completely in production build. I don't want this to be logging inside of my application terminal when its being run in production mode.

  12. itsmikesharescode commented on May 20, 2024

    @itsmikesharescode

    any update?

  13. 104 remaining items

  14. jdgamble555 commented on Nov 7, 2025

    @jdgamble555

    @rossvold - I believe the error actually is fixed, but both examples still use getSession(), which we no longer need to use.

    https://supabase.com/docs/guides/getting-started/tutorials/with-sveltekit
    https://supabase.com/docs/guides/auth/server-side/sveltekit

    Here is my SvelteKit repo copying the example User Management app. I didn't get any issues, but let me know if you do:
    https://github.com/jdgamble555/sveltekit-supabase-demo

    I'm working to help revamp the docs for all Frameworks:

    Follow the Docs Thread here:
    supabase/supabase#40985 (comment)

    J

  15. rossvold commented on Nov 7, 2025

    @rossvold

    @rossvold - I believe the error actually is fixed, but both examples still use getSession(), which we no longer need to use.

    https://supabase.com/docs/guides/getting-started/tutorials/with-sveltekit
    https://supabase.com/docs/guides/auth/server-side/sveltekit

    Here is my SvelteKit repo copying the example User Management app. I didn't get any issues, but let me know if you do:
    https://github.com/jdgamble555/sveltekit-supabase-demo

    I'm working to help revamp the docs for all Frameworks:

    Follow the Docs Thread here:
    supabase/supabase#40985 (comment)

    J

    I understand but this issue is not closed until the documentation is corrected then.

    I'm not going to NOT follow the documentation and do something undocumented to get it working.

  16. mandarini commented on Nov 7, 2025

    @mandarini
    Contributor

    @rossvold I undestand your very valid frustration. Please bear with us until we update the documentation. I will not close this issue until we update it, ok?

  17. jdgamble555 commented on Jan 21, 2026

    @jdgamble555

    @mandarini - Is this still being worked on? It's crazy to me the docs have been incorrect for this amount of time.

    J

  18. mandarini commented on Jan 22, 2026

    @mandarini
    Contributor

    @jdgamble555 I think there's another issue for that, including @ChrisChinchilla ? I have asked internally for this, please bear with us.

  19. chanmathew commented on Feb 13, 2026

    @chanmathew

    @mandarini any update on this? Every day this clutters our SSR logs and it's unbelievably frustrating how a simple thing like this has still not been resolved for over a year. I'm honestly about to migrate our paid account off Supabase because of this, not the mention the recent outage with no comms. So disappointed in Supabase.

    Image
  20. jdgamble555 commented on Feb 13, 2026

    @jdgamble555

    @chanmathew - IDK if they are ever going to update the docs as it has been a few months and they are "deep" into updating them still... I think they are not making this a priority.

    Either way, the actual issue is fixed if you implement it correctly. Here is my SvelteKit version:

    supabase/supabase#40985 (comment)

    J

  21. rossvold commented on Feb 13, 2026

    @rossvold

    @chanmathew - IDK if they are ever going to update the docs as it has been a few months and they are "deep" into updating them still... I think they are not making this a priority.

    Either way, the actual issue is fixed if you implement it correctly. Here is my SvelteKit version:

    supabase/supabase#40985 (comment)

    J

    Been running basically this config for 1 months and can confirm that it does work.

    I don't understand why they can't just update the 2 pages of documentation for this.

    Why spend time fixing this issue, and then completely ignore updating the correlating to the fix 😅😅

  22. ChrisChinchilla commented on Feb 17, 2026

    @ChrisChinchilla

    Hey all, regarding docs. There's a lot more than 2 pages of docs as part of the change, and until this week, the docs team was just me, and I was also on holiday last week. So, some things do take a little longer than I/we hope. But I am back on it this week, and several pages are already updated. Thanks!

  23. vehm commented on Feb 17, 2026

    @vehm

    Hey all, regarding docs. There's a lot more than 2 pages of docs as part of the change, and until this week, the docs team was just me, and I was also on holiday last week. So, some things do take a little longer than I/we hope. But I am back on it this week, and several pages are already updated. Thanks!

    Hoping this is the same sentiment for everyone in this thread, but the frustration expressed here is by no means directed at one person. I appreciate the work everyone has done on this, I just wish that this issue as a whole received attention sooner.

    Thank you for your work on this!

  24. magick93 commented on Mar 13, 2026

    @magick93

    So, is there a way to turn this annoying message off?

  25. jdgamble555 commented on Mar 13, 2026

    @jdgamble555

    @magick93 - problem is not longer turning off the message, but the docs need to be updated so the message won't be seen.

    See: supabase/supabase#40985 (comment)

    J

  26. mandarini commented on Jul 22, 2026

    @mandarini
    Contributor

    I think we can close this issue now. What do you think @jdgamble555 ?

  27. mandarini commented on Oct 16, 2026

    @mandarini
    Contributor

    Hi @j4crev, thank you for opening this issue! 💚

    Closing. Where this landed:

    The warning still fires when session.user properties are read on the server from an unverified cookie. That is intended.

    If it still shows on a current version with the current guide, open a new issue with a repro and the version.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

auth-jsbug

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions