ValidationError: "expiresInMinutes" is not allowed NodeJs JsonWebToken

node.jsJwt

node.js Problem Overview


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
        });
		
}

node.js Solutions


Solution 1 - node.js

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.

Solution 2 - node.js

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

Solution 3 - node.js

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"

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionAbdul Rehman SayedView Question on Stackoverflow
Solution 1 - node.jsAbdul Rehman SayedView Answer on Stackoverflow
Solution 2 - node.jskaxi1993View Answer on Stackoverflow
Solution 3 - node.jsedelansView Answer on Stackoverflow