Skip to content

Instantly share code, notes, and snippets.

@ynwd
Last active August 22, 2020 07:26
Show Gist options
  • Save ynwd/e6a4f80598f37fae28b0e1f9ebe48fa0 to your computer and use it in GitHub Desktop.
Save ynwd/e6a4f80598f37fae28b0e1f9ebe48fa0 to your computer and use it in GitHub Desktop.
Converting JWT callbacks to promises
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