Reputation: 7145
const jwt = require('jsonwebtoken');
module.exports = (req, res, next) => {
try {
const token = req.headers.authorization;
const decoded = jwt.verify(token, 'somes');
req.user = decoded.user;
next();
} catch (error) {
return res.status(401).json({
message: 'Auth failed',
});
}
};
This is my check-auth middle ware I've configured AirBnB coding standards for this expressjs project.
I got an linting error. What does this really mean and how can I get rid of this error? Is it okay to put return statement in front of the next() function call like this return next();
How does that affect to the code?
error Expected to return a value at the end of arrow function consistent-return
Upvotes: 1
Views: 798
Reputation: 11
In my case I had my function that is inside the hook useSelector and I was using it together with the keys
const petitions = useSelector((store) => {store.cachePetitions.results});
My solution only remove the keys and thus the error generated by eslint disappeared
const petitions = useSelector((store) => store.cachePetitions.results);
Upvotes: 1
Reputation: 1935
It's complaining that one of your code paths is returning a value, but the other isn't. Returning a value isn't necessary here.
Change
return res.status(401).json({
message: 'Auth failed',
});
to
res.status(401).json({
message: 'Auth failed',
});
Upvotes: 2