Created
October 3, 2017 20:24
-
-
Save Bensigo/355338d81c7501635c17c17f50f305e6 to your computer and use it in GitHub Desktop.
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 jwt = require('jsonwebtoken') | |
const config = require('./config') | |
module.exports = async req => { | |
// check for token in headers | |
const token = req.headers.authorization | |
try { | |
const {user} = await jwt.verify(token, config.SECRET) | |
// asign the user to req.user | |
req.user = user | |
} catch (err) { | |
console.log(err) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment