I keep trying to generate a jwt token, but after i input the code, the token won’t generate when i look at application cookies.
app.post(
"/login",
[
check("email", "Emaill length error")
.isEmail()
.isLength({ min: 10, max: 30 }),
check("password", "password length 8-10").isLength({ min: 8, max: 10 }),
],
(req, res) => {
const sql = "SELECT * FROM account WHERE email = ? AND password = ?";
db.query(sql, [req.body.email, req.body.password], (err, data) => {
const errors = validationResult(req);
if (!errors.isEmpty()) {
return res.json(errors);
} else {
if (err) {
return res.json("Error");
}
if (data.length > 0) {
const token = jwt.sign({ role: "user" }, "jwt_secret_key", {
expiresIn: "1d",
});
res.cookie("token", token);
return res.json("Success");
} else {
return res.json("Failed");
}
}
});
}
);