How Can I Access localstorage
from server Component?
#58434
Replies: 3 comments 1 reply
-
Well, the short It is the equivalent is trying to access the window innerWidth from a Server Component. That being said, Server Actions, are the alternative, to activate server side work, from the client, and use the result of calling that Server Action to populate the UI. It'd be the equivalent of doing Otherwise, you'd need to re-think your approach. It seems like you'd benefit from using httpOnly cookies, for this use case. |
Beta Was this translation helpful? Give feedback.
-
First of all, private data should never be stored in local storage, why not Now you can use http-only cookie or auth header for storing user token. Both have their pros and cons Also if you are using http-only cookie you will have to use https for development, because they can't be tested on localhost. |
Beta Was this translation helpful? Give feedback.
-
Hi @prkagrawal @clevermiraz, i have this code and i want a value from localStorage and the value is not a private data the value is for redirect the user when user come on the website , and this is not a api call from anywhere so i can't set the headers
then what should i do? |
Beta Was this translation helpful? Give feedback.
-
Is There Any Way to Get
localstorage
directly In the server component?Or Now I Think In the Server Component,
make a client Component then Get The
localstorage
from there then Use It.Basically, In
localstorage
we storeaccessToken
we need that For Fetching Private Data.Beta Was this translation helpful? Give feedback.
All reactions