0

I'm creating my first ever login system, using JsonWebTokens, and I've hit an obstacle trying to use the encode function.

My error message says:

if (this.ended && !this.hasRejectListeners()) throw reason; ^ TypeError: undefined is not a function

and I've managed to narrow the error down to this line of code:

var jwt = require('jsonwebtoken');

    jwt.encode(payload, superSecret);

The function this is a part of looks like this:

var moment = require('moment');
var jwt = require('jsonwebtoken');
var superSecret = require('../config/token.js').secret;

      function (user) {

        var payload = {
          sub: user._id,
          iat: moment().unix(),
          exp: moment().add(14, 'days').unix()
        };

        return = jwt.encode(payload, superSecret);

Needless to say, since this is the first time I'm authenticating anything, I don't know why this would cause an error. Please help.

martin
  • 1,894
  • 4
  • 37
  • 69

0 Answers0