Skip to content

Commit 758ca5e

Browse files
committed
temporarly fix an issue of double callback in JWS
1 parent bece881 commit 758ca5e

File tree

3 files changed

+6
-2
lines changed

3 files changed

+6
-2
lines changed

package.json

+1
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
"url": "https://github.com/auth0/node-jsonwebtoken/issues"
2020
},
2121
"dependencies": {
22+
"cb": "~0.1.0",
2223
"joi": "~6.10.1",
2324
"jws": "^3.0.0",
2425
"ms": "^0.7.1",

sign.js

+3
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ var Joi = require('joi');
22
var timespan = require('./lib/timespan');
33
var xtend = require('xtend');
44
var jws = require('jws');
5+
var cb = require('cb');
56

67
var sign_options_schema = Joi.object().keys({
78
expiresIn: [Joi.number().integer(), Joi.string()],
@@ -124,6 +125,8 @@ module.exports = function (payload, secretOrPrivateKey, options, callback) {
124125
var encoding = options.encoding || 'utf8';
125126

126127
if (typeof callback === 'function') {
128+
callback = callback && cb(callback).once();
129+
127130
jws.createSign({
128131
header: header,
129132
privateKey: secretOrPrivateKey,

test/async_sign.tests.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@ describe('signing a token asynchronously', function() {
2020

2121
it('should work', function (done) {
2222
jwt.sign({abc: 1}, "secret", {}, function (err, res) {
23-
expect(err).to.not.exist();
24-
done();
23+
expect(err).to.be.null();
24+
done();
2525
});
2626
});
2727

0 commit comments

Comments
 (0)