How to access cookies with ssr?
I have an app where you log in, which gives you two cookies, sessionId and userId. Then, on page load, I want to use that to show a little log in badge like the attached image, that calls a server function that returns user data, to then be put in the badge. How do I access cookies with ssr?
5 Replies
You access cookies through Vinxi. Here's an example:
Hope that helps,
Chris
If you're interested in learning more about Vinxi, this link will help: https://vinxi.vercel.app/api/server/cookies.html
Cookies | Vinxi
Vinxi Documentation
But where do I put this
I have been accessing the document object for cookies
But it gives an error when I do
I'll write a more detailed description when I get to my computer.
Ok. You'll import
getCookie
at the top of your file.
Next, you'll want to access your cookie on the server. You can do that in SolidStart with "use server";
. Here's an example of how you can use "use server";
inside of a function.
Alright, thanks