text: import jwt from 'jsonwebtoken';
  import secretKey from './secret-key';
  
  export default (req, res, next) => {
    const authHeader = req.get('Authorization');
    if (!authHeader) {
      req.isAuth = false;
      return next();
    }
    const token = authHeader.replace('Bearer ', '');
    if (!token || token === '') {
      req.isAuth = false;
      return next();
    }
    let decodedToken;
    try {
      decodedToken = jwt.verify(token, secretKey.KEY);
    } catch (err) {
      req.isAuth = false;
      return next();
    }
    if (!decodedToken) {
      req.isAuth = false;
      return next();
    }
    req.isAuth = true;
    req.userId = decodedToken.userId;
    return next();
  };
  