Last active
November 3, 2023 09:22
-
-
Save neos1803/d5fc4e935ad81d37887f46d98f6dd929 to your computer and use it in GitHub Desktop.
Sync and Async way of Verifying and Signing JWT
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 { sign } = require('jsonwebtoken') | |
const token = new Promise((resolve, reject) => { | |
sign({ data: "Your Data" }, "Your_Secret", {}, (err, token) => { | |
if (err) reject(err); | |
else resolve(token) | |
}); | |
}); |
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 { verify } = require('jsonwebtoken') | |
const data = new Promise((resolve, reject) => { | |
verify(token, "Your_Secret", (err, payload) => { | |
if (err) reject(err); | |
else resolve(payload); | |
}); | |
}) |
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 { sign } = require('jsonwebtoken') | |
const token = sign({ data: "Your Data" }, "Your_Secret"); |
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 { verify } = require('jsonwebtoken') | |
const data = verify(token, "Your_Secret"); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment