Last active
February 24, 2020 16:39
-
-
Save heytulsiprasad/87cc908b96939b74d41cbd31ff49d566 to your computer and use it in GitHub Desktop.
gist overviewing methods under jsonwebtoken to generate and verify jwts
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
// we are going to explore jsonwebtoken methods | |
const jwt = require("jsonwebtoken") | |
const myFunction = async () => { | |
const token = jwt.sign({ _id: "abcdefg" }, "anysecretkey", { | |
expiresIn: "10 seconds" | |
}) | |
console.log(token) | |
// eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJfaWQiOiJhYmMxMjMiLCJpYXQiOjE1ODI1NjA4MzMsImV4cCI6MTU4MjU2MDgzOH0.KCjzcuHyg0VS-GVN8OnE_jqTh3LtixMGM3iqjUfeZoI | |
const data = jwt.verify(token, "anysecretkey") | |
console.log(data) | |
// { _id: 'abc123', iat: 1582560833, exp: 1582560838 } | |
} | |
myFunction(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment