All files / src/middlewares validate-jwt.js

100% Statements 13/13
100% Branches 2/2
100% Functions 1/1
100% Lines 13/13

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 334x   4x 19x   19x 1x         18x 18x         17x 17x 17x   1x         17x     4x      
const jwt = require('jsonwebtoken');
 
const validateJWT = (req, res, next) => {
  const token = req.header('x-token');
 
  if (!token) {
    return res.status(401).json({
      ok: false,
      message: 'there is no token in the request',
    });
  }
  try {
    const { uid, fullName, email } = jwt.verify(
      token,
      process.env.SECRET_JWT_SEED_SLACK
    );
 
    req.uid = uid;
    req.fullName = fullName;
    req.email = email;
  } catch (err) {
    return res.status(401).json({
      ok: false,
      message: ' invalid token',
    });
  }
  next();
};
 
module.exports = {
  validateJWT,
};