Getting "TypeError: res.status is not a function."
Getting "TypeError: res.status is not a function."
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;
Error ScreenShot
应该是req, res, next
改变
function auth(res, req, next) {
到
function auth(req, res, next) {
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;
Error ScreenShot
应该是req, res, next
改变
function auth(res, req, next) {
到
function auth(req, res, next) {