Next.js Discord

Discord Forum

How to get "xyz" req.cookie in jwt middleware using Fetch

Unanswered
Holland Lop posted this in #help-forum
Open in Discord
Avatar
Holland LopOP
I have set a cookie in req.cookie when user logs in. This cookie is being received from the client-side through Axios but not on through fetch. How can this be resolved?

I attached 4 screenshots,
1- Setting Cookie in res whenever user logs in
2- Jwt Middleware to authenticate user
3- Frontend Api using fetch
4- two backend consoles, first one is from axios "path: '/api/auth/user'" (I m getting req.cookies here)
second one is from fetch path: '/notifications/user/:page (I m not getting any cookies in req.cookies)




next: 14.0.2
Image
Image
Image
Image

6 Replies

Avatar
Ray
did you set the header with axios?
Avatar
Holland LopOP
nope
Avatar
Ray
have you tried make a request to /api/auth/user with fetch?
Avatar
Holland LopOP
oh, wait lemme check
@Ray
Image
Avatar
Ray
hmm, not sure what happen yet, need to see more code. could you share the repo?