In my backend I’ve set the following endpoint
router.post("/sign-in", async (req, res) => {
try {
//Extracting email and password from the req.body object
const { email, password } = req.body;
//const test = res.json({requestBody: req.body});
const JWT_SECRET = 'secret';
//Comparing provided password with password retrived from database
bcrypt.compare(password, '$2a$12$nAgntW7OmjekzLI2oX1h9u5yPRvQRpenm/E3jhBT1.HZncUpFYsuu', (err, result) => {
if (result) {
const token = jwt.sign( '[email protected]' , JWT_SECRET);
return res
.header("Access-Control-Allow-Origin", "*")
.header("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept")
.status(200)
.json({ message: "User Logged in Sucessfully", token });
}
console.log(err);
return res.status(401).json({ message: "Invalid Credentials" + password});
});
} catch (error) {
res.status(401).send(err.message);
}
});
Then from the front end I am calling it like this
const login = (username, password) => {
return axios
.post(API_URL + "sign-in", {
username,
password,
})
.then((response) => {
if (response.data.accessToken) {
localStorage.setItem("user", JSON.stringify(response.data));
}
return response.data;
});
};
However I get a cors error, I have even disabled CORS on firefox but to no avail.
Any ideas what could be causing this?
I’ve tried adding the allow-origin headers and disabling cors in firefox