Can not get custom cookie on serverSideProps #15854
Unanswered
shoaibsharif
asked this question in
Help
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Bug report
I apologize if it already has been discussed or described. I cannot find the cookies on
serverSideProps
context.Describe the bug
When I request a query with apollo-client to set a cookie, it sets the cookie on browser but on
serverSideProps
I can not find the cookie. but with Apollo Client, it works on client side. I even get the same issuewith-apollo
example. i thought at first it's a apollo-client issue but it turns out, I can't pass cookie on server side withserverSideProps
. For some reason, this issue doesn't happen onlocalhost
. It only is giving me issue when it is hosted (or so to say production).To Reproduce
Here I have a simple version to reproduce the behavior
If you go to the codesandbox link above, you will see
John Doe
when you clicklogin
(which is expected). When you click Login, it will set a cookie nametoken
withmyToken
value. Then if you reload the page, you will see{me : null}
. Whatme
is representing that it reads thereq.cookies.token
on the server and returnJohn Doe
if it finds it otherwise it will returnnull
. On the other hand if you click on client link and without clickingLogin
button if you refresh the page, you will see{me : John Doe}
which means that it reads the cookie on the client side.Expected behavior
I should able to recieve cookies on server side via getServerSideProps.
System information
Additional context
This is very weird that I can't reproduce such behavior when I run the project on development(localhost). I have tried to deploy Netlify, heroku, vercel. I get the same issue on everywhere. I always thought, it is a issue on apollo-client but it can't pass the cookie to apollo-client from
serverSideProps
context.req.header.cookie.Beta Was this translation helpful? Give feedback.
All reactions