TypeError: res.status is not a function at auth (D:PROJECTWeb ApplicationLearning ReactMERN STACKmiddlewareauth.js:17:9). I am getting this error. The code is given below.
JavaScript
x
22
22
1
const config = require("config");
2
const jwt = require("jsonwebtoken");
3
4
function auth(res, req, next) {
5
const token = req.header("x-auth-token");
6
7
// Check for token
8
if (!token) res.status(401).json({ msg: "No token, authorization denied" });
9
10
try {
11
// verify token
12
const decoded = jwt.verify(token, config.get("jwtSecret"));
13
// Add user from payload
14
req.user = decoded;
15
next();
16
} catch (e) {
17
res.status(400).json({ msg: "Token is not valid" });
18
}
19
}
20
21
module.exports = auth;
22
Advertisement
Answer
It should be req, res, next
Change
JavaScript
1
2
1
function auth(res, req, next) {
2
to
JavaScript
1
2
1
function auth(req, res, next) {
2