#How do you fetch and share authedUser throughout the app?

18 messages · Page 1 of 1 (latest)

vast linden
#

I tried several methods and I've landed on fetching the user in the middleware and then passing it to the _app.tsx through the headers and then sharing it with context. Please let me know if this is a right approach.

hollow driftBOT
#

🔎 This post has been indexed in our web forum and will be seen by search engines so other users can find it outside Discord

🕵️ Your user profile is private by default and won't be visible to users outside Discord, if you want to be visible in the web forum you can add the "Public Profile" role in id:customize

✅ You can mark a message as the answer for your post with Right click -> Apps -> Mark Solution
(if you don't see the option, try refreshing Discord with Ctrl + R)

vast linden
distant drum
vast linden
#

I am using old pages router. Is this still relevant?

Maybe it is just better to fetch authedUser on client side?

carmine python
#

@vast linden How do you consume the user data on your pages?

vast linden
#

I take it out from the pageProps in the _app.tsx and then share it with context. But with this approach I have to fetch authedUser in every single route using getServerSideProps, to make it available under pageProps inside _app.tsx. Which is not ideal, because it does not let me use static generation

#

The reason I need it on every page is because I need user info in layout to show in the navigation bar

carmine python
#

well, your approach is not correct

#

you want to show user data in the navigation bar but you still want SSG

#

it doesn't make sense

#

static generation happens in build time and at that moment you don't know auth user

vast linden
#

yeah. I know it is not correct, that's why I am asking which would be the best approach, to fetch authed user on client side? What would you recommend

carmine python
#

from your previous messages, I guess you are on the page router, right?

#

You can fetch user data from the client side and store it in your global state

vast linden
#

Thanks

carmine python
vast linden
#

I do. but I could not fetch it inside layout since I was using SSR