Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Error: invalid expiresIn option for string payload

Tags:

javascript

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)
})
like image 201
Howie Avatar asked Feb 03 '26 11:02

Howie


1 Answers

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});
like image 166
Rifat Bin Reza Avatar answered Feb 05 '26 01:02

Rifat Bin Reza



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!