Next.js Discord

Discord Forum

Need help with SSR authentication in new app directory

Answered
idan posted this in #help-forum
Open in Discord
Avatar
idanOP
Hi everyone,
I recently transitioned to using the new app directory a few weeks back and I'm still finding my footing when it comes to tackling various issues.

I have a server function that communicates with my server to fetch the current user's details using an authorization token header.

My aim is to use this function within my app layout because I'd like to avoid running it every time users navigate between pages - it just doesn't seem efficient.

One roadblock I'm encountering is that I can't use React Context or other state management libraries since they require the "use client" directive, which I'd rather not use in this scenario.

My question is, how could I pass the user object to all child components within the layout?

I'm open to the possibility that I might not be approaching this in the most effective way, so any feedback or alternative solutions would be really appreciated.

Looking forward to your help,
Thanks!
Answered by idan
Found a solution - ended up using React Context and fetching the data in the server side.
View full answer

1 Reply

Avatar
idanOP
Found a solution - ended up using React Context and fetching the data in the server side.
Answer