How to handle user session information with SSR? How to get session details in component when doing SSR? #10039
Unanswered
AndrewRayCode
asked this question in
Help
Replies: 1 comment 1 reply
-
Did you manage to solve this? I considered using https://github.com/moshest/next-client-cookies, but I'm not sure how to make it work with Auth.js. |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
I have a header component in my app:
I'm using SSR, standard modern practice for fast applications. However
useSession()
returnsnull
for the server render of this component, so the page first renders without the user's name in the header, then the client re-renders, causing a flash to show the name. It's jarring.We can't call hooks conditionally, otherwise I could do something like
And you can't call both because the server one barfs in the client
I have a bad hack workaround solution to wrap every
getServerSideProps
with a higher order function that reads the session user, injects it into the SSR props, and then I wrap every client component with a HOC that provides this session user prop to a context provider, so components like the Header can read it from context, injected into SSR props. But all I'm trying to do is read the session in a way that supports SSR, so this is a really heavyweight hoop to jump through.I assume this issue is dependent on getting cookies in the component at SSR render time in React, which I'm not sure if it's possible?
Beta Was this translation helpful? Give feedback.
All reactions