Created
January 20, 2018 15:50
-
-
Save davidbarral/7e5acc7bcac41e11ea74c0313a1b1ece to your computer and use it in GitHub Desktop.
Promisify: adhoc promisify
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const jwt = require("jsonwebtoken"); | |
const promisify = fn => (...args) => new Promise((resolve, reject) => { | |
fn(...args, (error, value) => { | |
if (error) { | |
reject(error); | |
} else { | |
resolve(value); | |
} | |
}); | |
}); | |
const jwtVerify = promisify(jwt.verify); | |
const verifyToken = token => jwtVerify(token, CERTIFICATE, { algorithms: ["RS256"] }); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment