If I hardcode the token from console.log(token); it works but doesn t work like this
const jwt = require( jsonwebtoken );
module.exports = async (req, res, next) => {
const authorization = req.headers.authorization;
let token = authorization.split( )[1];
try {
console.log(token);
const decoded = jwt.verify(token, secret key );
req.email = decoded.email;
next();
} catch (e) {
console.error(e);
}
};
it returns
JsonWebTokenError: invalid token