I have a problem with my server while trying to send cookies. I am currently working on an api, when I try the code on Postman, the cookies get sent, but not on the browser. This is my current configuration.
// my current server code that sends the cookie //
function sendCookie(user, statusCode, res) {
const token = signToken(user._id);
const cookieOptions = {
expires: new Date(
Date.now() + process.env.JWT_COOKIE_EXPIRES_IN * 24 * 60 * 60 * 1000
),
httpOnly: true,
};
process.env.NODE_ENV === "production" ? (cookieOptions.secure = true) : "";
res.cookie("session", token, cookieOptions);
}
//frontend code sending the ajax request to the api
async function login(email, password) {
try {
const res = await axios({
method: "POST",
url: "http://127.0.0.1:3000/api/v1/users/login",
data: {
email,
password,
},
withCredentials: true,
});
} catch (err) {
console.log(err);
}
}
//configuration for cors
app.use(
cors({
origin: true,
credentials: true,
})
);
app.options(
"*",
cors({
origin: true,
credentials: true,
})
);
still with all these configurations The cookies are being sent to the browser
Thanks...