Skip to content

Commit

Permalink
fix(utils): addded error handling for expired token
Browse files Browse the repository at this point in the history
  • Loading branch information
HoseaCodes committed Mar 16, 2022
1 parent 9c7dfd5 commit aaa54a9
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions utils/auth.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,15 @@ const auth = (req, res, next) => {
return res.status(400).json({ msg: "Invalid Authentication - no token" });

jwt.verify(token, process.env.ACCESS_TOKEN_SECRET, (err, user) => {
if (err)
if (err instanceof jwt.TokenExpiredError) {
return res
.status(400)
.json({ msg: "Token Expired Error", err});
}
if (err)
return res
.status(400)
.json({ msg: "Invalid Authentication - invalid token" });
.json({ msg: "Invalid Authentication - invalid token"});

req.user = user;
next();
Expand Down

0 comments on commit aaa54a9

Please sign in to comment.