English 中文(简体)
Why can t I pass my token without hardcoding?
原标题:

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

问题回答

暂无回答




相关问题
intercept a log from winstonjs and inject arguments

Is it possible to inject an argument into a log such as error, debug or info using the winston configuration (createLogger)? I d like to be able to intercept the log and inject an object into each log

Why can t I pass my token without hardcoding?

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....

Writing to files in Node.js

I ve been trying to find a way to write to a file when using Node.js, but with no success. How can I do that?

热门标签