Cookie from backend not getting set in frontend
Hi devs, I am trying to set the jwt token as the cookie from backend but I am not seeing that getting set in the Applications tab in the browser.
Too much to ask maybe, but if someone is available can we connect. I can walkthrough the code whatever I am trying to do.
I am just stuck and not able to proceed with my project.
9 Replies
I have pasted the generateToken and protectRoute file. protectRoute I am using to check if the request already has the token then only execute the controller
so I am giving like this
app.get("/", protectRoute, someController)
The function for set cookie when is it invoked?
Ideally you should be able to screenshot the response headers that contain the cookie in the network tab of the browser.
yes I am able to see the cookie in the response header but does it get saved to Applications tab also in thr browser?
function for setCookie is invoked during login @Hashi
Well I guess if you are using chrome it should show under Application => Cookies.
right, thats what I also thought of. But I am not seeing. Now when I am trying to send a request again to the backend, in the protectRoute where I am trying to find the token using req.cookies.jwt, its coming as undefined
so I am never able to execute the controller since protectRoute logic didnt work
I am seeing the it here in response headers
If there is no cookie showing, and there is no cookie send with the request there is no need to debug the code related to "protectRoute".
First I would check if there is really "Set-Cookie" header being send upon login.
If you can see it then, maybe you have invalid cookie value and the browser is ignoring "Set-Cookie" header
the screenshot I pinged just now, I can see the Set-Cookie in the response header
I would guess there is domain difference maybe, like your cookie is being set to "localhost:5173" but you are trying to access it from "localhost:5000"