Hi there,
Can anyone please help me out here?
I am writing this syntax:
const jwt = require("jsonwebtoken");
const generateToken = (data) => {
return new Promise((ok, not) => {
jwt.sign(data, process.env.TOKENKEY, { expiresIn: "7d" }, (err, token) => {
if (err) not(err);
else ok(token);
});
});
};
and calling this function in a try-catch syntax like this:
let data = await JWT.generateToken(req.body.us);
console.log('token ', data);
but I keep getting the following error:
“err Error: invalid expiresIn option for string payload
at Object.module.exports [as sign] (C:\fullstack\node.js\final project\Node_Project\node_modules\jsonwebtoken\sign.js:128:22)”
*** without the “expiresIn”, it works perfectly.