I am trying to store the auth token in the cookie once the user logged into the system. Then I want to use the auth token for subsequent requests. When I console (‘req.cookies’: req.cookies) the output is [Object: null prototype] {}
I have tried a lot but was unable to solve the issue, I got the set-cookie in the response header but not on the Application Tab of the console. However, it works fine with Postman.
Frontend is running on: http://merchant.localhost:3000
Backend is running on: http://127.0.0.1:8080
I’m using cookie-parser
I have configured the cors and cookie-parser as follows.
app.use(cookieParser());
app.use(cors({
origin: 'http://merchant.localhost:3000',
credentials: true,
}));
This is how I have stored the token in the cookie.
res.cookie("authToken", authToken, {
httpOnly: true,
secure: false,
sameSite: "None",
domain: "localhost",
});
Below is the image of my response header.
Below is the image of the Application Tab.
for subsequent requests, I pass credentials: ‘include’, but still it is not working.
fetch("http://127.0.0.1:8080/api/produce/add", {
method: "POST",
credentials: 'include',
body: formData,
})
I have tried clearing the cookies and browsing data and with different browsers. Also, tried with the incognito tab as well. But, nothing works.