Skip to content

Instantly share code, notes, and snippets.

@Bensigo
Created October 3, 2017 20:24
Show Gist options
  • Save Bensigo/355338d81c7501635c17c17f50f305e6 to your computer and use it in GitHub Desktop.
Save Bensigo/355338d81c7501635c17c17f50f305e6 to your computer and use it in GitHub Desktop.
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