Skip to content

Instantly share code, notes, and snippets.

@davidbarral
Created January 20, 2018 15:50
Show Gist options
  • Save davidbarral/7e5acc7bcac41e11ea74c0313a1b1ece to your computer and use it in GitHub Desktop.
Save davidbarral/7e5acc7bcac41e11ea74c0313a1b1ece to your computer and use it in GitHub Desktop.
Promisify: adhoc promisify
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