提问者:小点点

正在获取“TypeError:Res.Status不是函数”。


TypeError:Res.Status不是auth的函数(D:\Project\Web Application\Learning React\Mern Stack\Middleware\auth.js:17:9)。我得到了这个错误。代码如下所示。

const config = require("config");
const jwt = require("jsonwebtoken");

function auth(res, req, next) {
  const token = req.header("x-auth-token");

  // Check for token
  if (!token) res.status(401).json({ msg: "No token, authorization denied" });

  try {
    // verify token
    const decoded = jwt.verify(token, config.get("jwtSecret"));
    // Add user from payload
    req.user = decoded;
    next();
  } catch (e) {
    res.status(400).json({ msg: "Token is not valid" });
  }
}

module.exports = auth;

错误截图


共1个答案

匿名用户

它应该是请求,res,next

改变

function auth(res, req, next) {

function auth(req, res, next) {

https://expressjs.com/en/guide/using-middleware.html