I am trying to set the expiresIn function in my javascript app. I am following the documentation, but I keep getting this error. Can anyone see what I am doing wrong?
app.get("/user", async (req, res) => {
const { name } = req.body;
const accessToken = jsonwebtoken.sign( name, process.env.ACCESS_TOKEN_SECRET, { expiresIn: 60 * 60});
res.json({ accessToken: accessToken, name })
console.log(accessToken, name)
})
Your payload needs to be an object otherwise it's treated as a string. Try this
const accessToken = jsonwebtoken.sign( {name: name}, process.env.ACCESS_TOKEN_SECRET, { expiresIn: 60 * 60});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With