Skip to content

Commit

Permalink
refactor(auth middleware): tell user if no token was provided
Browse files Browse the repository at this point in the history
Let the user know if a token was provided or not, or whether it was
provided and is invalid
  • Loading branch information
chidimo committed May 26, 2019
1 parent 0008be0 commit e3cead2
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions middleware/authentication.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,13 @@ const AuthenticationMiddleware = {
return next();
}
const token = req.headers['x-access-token'];
if (!token) {
const msg = 'Include a valid token in the x-access-token header';
return res.status(422).json({
error: 'No token provided',
msg
});
}
try {
req.user = jwt.verify(token, Settings.jwtSecret);
req.token = token;
Expand Down

0 comments on commit e3cead2

Please sign in to comment.