Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ValidationError: "expiresInMinutes" is not allowed NodeJs JsonWebToken

Tags:

node.js

jwt

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         });  } 
like image 590
Abdul Rehman Sayed Avatar asked Jun 04 '16 11:06

Abdul Rehman Sayed


1 Answers

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.

like image 105
Abdul Rehman Sayed Avatar answered Sep 23 '22 11:09

Abdul Rehman Sayed