SSR component variable
Unanswered
Drentse Patrijshond posted this in #help-forum
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?
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
@Drentse Patrijshond 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?
you can get cookies thought the [cookies() function](https://nextjs.org/docs/app/api-reference/functions/cookies) on serverside. However: it's NOT save to store a
isAdmin variable clientside without any encryption or anything else to make it saveHello 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.
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