Passing cookies from frontend to backend

Hello everyone I am new to webdev and using the render for hosting my MERN stack websites.my MERN stack website is actually booking website for hotels. I have hosted the client and the backend on different subdomain of render.com in my client when I login in to the server I am getting a cookie in response headers which I have configured to be generated in my server through jwt the code is res.cookie(‘access_token’, token,{httpOnly:true,sameSite:None,secure:true}.status(200).send(“you have logged in successfully”) but when I am making subsequent requests to the server like deleting a user details or delete a hotel reservation I am getting an error 401 and I am seeing that in the request headers the cookie is not being passed the code for sending another request const res= await axios.delete(‘https://hotelbookingbackend.onrender.com’,{with credentials:true}). I have set the cors policy to accept requests from origin of client render hosted website url but it is still not working how to fix this ??

Hi there,

HTTP 401 means “Unauthorized”. What you’re describing here are typically code issues and not something we can assist much with. I recommend searching this community forum as well as the broader internet for assistance here.

Let us know if you have any further questions.

Regards,
Mike


Render Support Engineer, MT (UTC-6, UTC-7 in Winter)

Thank you for replying. In my server code i have set return status 401 when the token is not present in the request headers i want to understand why the token is not being passed as a cookie . When I first login to the server I get the cookie in the set-cookie of the response headers from the server but in subsequent requests made to the server from the same client the cookie is not being passed in the request headers

Hi there,

Render shouldn’t be doing anything to interfere with this header.

Are you seeing any specific errors around why this header isn’t being set? Can you provide some more detail about how you’re setting this header, and any other relevant attributes/headers your setting here? https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Set-Cookie

Regards,
Mike


Render Support Engineer, MT (UTC-6, UTC-7 in Winter)

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.