Bluebird: Error in promisifyAll(jsonwebtoken)

Created on 8 Jul 2015  路  2Comments  路  Source: petkaantonov/bluebird

When I try to promisifyAll(jsonwebtoken), the function jwt.signAsync(token, secretOrPublicKey) doesn't work properly.

Most helpful comment

@benjamingr @kikar i experiencing the same problem. jwt.sign actually has a last optional callback parameter, see.

Promise.promisifyAll(jwt);

....

jwt
  .signAsync(data, config.jwtSecret, { expiresIn: '1h' })
  .then(token => {
    console.log('TOKEN: ', token);
  })
  .catch(err => {
    // for some reason it will run to the catch with err as the token
    console.log('TOKEN: ', err);
  });

EDIT: it is a jsonwebtoken issue, same thing happens with:

jwt.sign(data, config.jwtSecret, { expiresIn: '1h' }, function(err, token) {
  console.log(err);
});

All 2 comments

sign is a synchronous function, you don't need to - and shouldn't, promisify those.

Promisification is for callback taking functions. Just use the API as synchronous.

var token = jwt.sign(token, secretOrPublicKey)

(Promisification would work for the async function in jsonwebtoken fine :))

@benjamingr @kikar i experiencing the same problem. jwt.sign actually has a last optional callback parameter, see.

Promise.promisifyAll(jwt);

....

jwt
  .signAsync(data, config.jwtSecret, { expiresIn: '1h' })
  .then(token => {
    console.log('TOKEN: ', token);
  })
  .catch(err => {
    // for some reason it will run to the catch with err as the token
    console.log('TOKEN: ', err);
  });

EDIT: it is a jsonwebtoken issue, same thing happens with:

jwt.sign(data, config.jwtSecret, { expiresIn: '1h' }, function(err, token) {
  console.log(err);
});
Was this page helpful?
0 / 5 - 0 ratings

Related issues

rainabba picture rainabba  路  5Comments

popod picture popod  路  4Comments

divramod picture divramod  路  5Comments

julien-f picture julien-f  路  5Comments

rohitbegani picture rohitbegani  路  6Comments