Home > Mobile >  console.log not shown in my local terminal
console.log not shown in my local terminal

Time:05-11

In my server site all works fine. but When I checked anything by console. log('anything') it doesn't show. here are some codes. they work fine. only I cannot see the console.log.

function varifyToken(req, res, next) {
    const getToken = req.headers.authorization;
    console.log('gettoken',getToken);
    next();
}

CodePudding user response:

According to the documentation, you should use something like this

function varifyToken(req, res, next) {
  const getToken = req.get('authorization');
  console.log('gettoken',getToken);
next();

}

Please check express documentation

CodePudding user response:

Thanks @teduhAfriyoko but still now> console.log('getToken') don't show in my local terminal; Updated Code is but my project work fine>

function varifyToken(req, res, next) {
const getToken = req.headers.authorization;
console.log(getToken);
if (!getToken) {
    return res.status(401).send({ message: 'UnAuthorized' });
}
const token = getToken.split(' ')[1];
jwt.verify(token, process.env.ACCESS_TOKEN, (err, decoded) => {
    if (err) {
        return res.status(403).send({ message: 'Forbidden' });
    }
    else {
        req.decoded = decoded;
        next();
    }
})

}

  • Related