When I try to promisifyAll(jsonwebtoken), the function jwt.signAsync(token, secretOrPublicKey) doesn't work properly.
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);
});
Most helpful comment
@benjamingr @kikar i experiencing the same problem.
jwt.signactually has a last optional callback parameter, see.EDIT: it is a
jsonwebtokenissue, same thing happens with: