Next.js Discord

Discord Forum

SSR component variable

Unanswered
Drentse Patrijshond posted this in #help-forum
Open in Discord
Drentse PatrijshondOP
So when i login i call a function to store an isAdmin boolean value as a cookie. now whenever i want to fetch that value from the client side its there. The question now is for server components when i want to fetch this value so i have to fetch it each time i navigate from one page to another or isn there a way where i can have persistant variable throught the navigation.

In short i have a value and when i refresh the page i need to refetch it. Can i fetch it once and use it thorught out the nvigatio nand refetch it when i refresh or login again?

3 Replies

Hello there!

From what i've understand you lost your value when you navigate between pages ?
I dont think so the issue is SSR related.

You can create a middleware which will get your cookies and set the value into your fetch headers so you have to do it once if that server related nonetheless you can use a store lib for client side if you want to get it from anywhere.
Drentse PatrijshondOP
Thanks