Last active
August 22, 2020 07:26
-
-
Save ynwd/e6a4f80598f37fae28b0e1f9ebe48fa0 to your computer and use it in GitHub Desktop.
Converting JWT callbacks to promises
This file contains hidden or 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
import jwt from "jsonwebtoken"; | |
export function tokenService() { | |
const SECRET = "secret"; | |
return new Promise<string>((resolve, reject) => { | |
jwt.sign( | |
{ foo: "bar" }, | |
SECRET, | |
(err: Error, token: string) => { | |
if (err) reject(err); | |
resolve(token); | |
}, | |
); | |
}); | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment