Is it okay to do fetching in layout.tsx?
Answered
zhefciad posted this in #help-forum
zhefciadOP
I have a navbar in my layout.tsx. Should I fetch it in layout and pass it down to navbar or should I fetch it inside my Navbar which is a client component? What's the standard?
Answered by B33fb0n3
fetch it only if it's part of layout. For example when you load the navigation links from a database, then this data is part of the layout. So you want to fetch it
8 Replies
@zhefciad I have a navbar in my layout.tsx. Should I fetch it in layout and pass it down to navbar or should I fetch it inside my Navbar which is a client component? What's the standard?
fetch it only if it's part of layout. For example when you load the navigation links from a database, then this data is part of the layout. So you want to fetch it
Answer
zhefciadOP
in my case it's the userProfile from my auth, so I guess I should fetch it in the client?
@zhefciad in my case it's the userProfile from my auth, so I guess I should fetch it in the client?
Only do that, if it's secure. How to know if it's secure? Read the readme: https://github.com/eric-burel/securing-rsc-layout-leak
zhefciadOP
thank you
sure thing. Please mark solution
Just an option, something I do at work, when the user authenticates I write back a nav only cookie, which the navbar relies on for rendering.... Someone could manipulate that cookie because its plan json.... but thats just them manipulating the UI, there is still checks on navigation to ensure they are allowed to access the page.
Just my two cents on it.
Just my two cents on it.
@Jboncz Just an option, something I do at work, when the user authenticates I write back a nav only cookie, which the navbar relies on for rendering.... Someone could manipulate that cookie because its plan json.... but thats just them manipulating the UI, there is still checks on navigation to ensure they are allowed to access the page.
Just my two cents on it.
zhefciadOP
that is genius, will do that in my app