70

I am using NodeJs with JsonWebtoken Module.

I am facing this error when calling sign method of json web token

ValidationError: "expiresInMinutes" is not allowed

var jwt = require('jsonwebtoken');

exports.authenticate = function(req, res, next) {
    var user = {"Name":"Abdul"} //static data for test purpose.

    var token = jwt.sign(user, req.app.get('jwtTokenSecret'), {
          expiresInMinutes: 1440 // expires in 24 hours
        });

        // return the information including token as JSON
        res.json({
          success: true,
          message: 'Enjoy your token!',
          token: token
        });

}

3 Answers 3

132

Ok I found that from https://www.npmjs.com/package/jsonwebtoken

You have to call expiresIn rather than expiresInMinutes.

 var token = jwt.sign(user, req.app.get('jwtTokenSecret'), {
           expiresIn : 60*60*24
         });

Here the value of expiresIn is measured in seconds rather than minutes, so the value has to be put in properly.

4
  • 1
    var token = jwt.sign(user, req.app.get('jwtTokenSecret'), { expiresIn : 60*24; // expires in 24 hours }); Jul 30, 2016 at 7:07
  • 3
    @MahmoudElgohary from the doc : "expiresIn: expressed in seconds " Jul 30, 2016 at 13:55
  • 6
    Please do not to what @MahmoudElgohary just suggested. That would expire in 24 MINUTES, not hours. For hours, use {expiresIn : 'xh'} where x is any number. example: {expiresIn : '24h'} Dec 8, 2016 at 3:54
  • thanks man :+1: , next time i'll look at documentation first before stack overflowing :joy:
    – anztrax
    Feb 23, 2017 at 12:12
24

expiresInMinutes was deprecated, you should use expiresIn: '1440m' for instance

8

expiresInMinutes is deprecated, use expiresIn instead. From the docs :

expiresIn: expressed in seconds or a string describing a time span rauchg/ms. Eg: 60, "2 days", "10h", "7d"

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.