12345678910111213141516171819 |
- const jwt = require('jsonwebtoken')
- module.exports = (req, res, next) => {
- if (req.method === 'OPTIONS') {
- return next()
- }
- try {
- const token = req.headers.authorization.split(' ')[1]
- if (!token) {
- return res.status(401).json({ message: 'no autorization' })
- }
- const decod = jwt.verify(token, config.get('jwtSecret'))
- req.user = decoded
- next()
- } catch (e) {
- res.status(401).json({ message: 'no autorization' })
- }
- }
|