text: import jwt from 'jsonwebtoken';
  import { promisify } from 'util';
  
  import authConfig from '../../config/auth';
  
  const error = { error: 'Token not provided.' };
  
  export default async (req, res, next) => {
    const authHeader = req.headers.authorization;
  
    if (!authHeader) return res.status(401).json(error);
  
    const [, token] = authHeader.split(' ');
  
    try {
      const { id } = await promisify(jwt.verify)(token, authConfig.secret);
      req.userId = id;
    } catch (err) {
      return res.status(401).json(error);
    }
  
    return next();
  };
  