Skip to content

Instantly share code, notes, and snippets.

@onejohi
Created November 12, 2019 09:53
Show Gist options
  • Save onejohi/9e00913afae1251cec9a1a2b46aa2aa2 to your computer and use it in GitHub Desktop.
Save onejohi/9e00913afae1251cec9a1a2b46aa2aa2 to your computer and use it in GitHub Desktop.
const { sign, verify } = require("jsonwebtoken");
module.exports = {
verifyJWToken(req, res, next) {
if (req.headers.authorization) {
const token = req.headers.authorization.split(" ")[1];
verify(token, 'secretword', { complete: true }, (error, decoded) => {
if (error) { res.json({ ok: false, error }) }
if (decoded ) { next() }
});
} else { res.json({ ok: false, error: { code: 403, name: 'Forbidden!'}}); }
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment