middleware/auth.js
/*The purpose of this function here is to get
the token that's sent from either react
or postman angular whatever front-end
you're using where it's gonna send along
a token*/
The purpose of this function here is to get
the token that's sent from either react
or postman angular whatever front-end
you're using where it's gonna send along
a token
The purpose of this function here is to get the token that ' s sent from either react or postman angular whatever front - end you ' re using where it ' s gonna send along a token
function auth(req, res, next) {
  const token = req.header('x-auth-token');
  if (!token)
    return res.status(401).json({ msg: 'No token, authorizaton denied' });
  try {
    const decoded = jwt.verify(token, jwtSecret);
    req.user = decoded;
    next();
  } catch (e) {
    res.status(400).json({ msg: 'Token is not valid' });
  }
}
function auth ( req , res , next ) { const token = req . header ( 'x-auth-token' ) ; if ( ! token ) return res . status ( 401 ) . json ( { msg : 'No token, authorizaton denied' } ) ; try { const decoded = jwt . verify ( token , jwtSecret ) ; req . user = decoded ; next ( ) ; } catch ( e ) { res . status ( 400 ) . json ( { msg : 'Token is not valid' } ) ; } }
The purpose of this function here is to get
the token that's sent from either react
or postman angular whatever front-end
you're using where it's gonna send along
a token
The purpose of this function here is to get the token that ' s sent from either react or postman angular whatever front - end you ' re using where it ' s gonna send along a token
// Check for token if it exists // Verify token // Add user from payload