Skip to content

Commit

Permalink
Fixes token expire error handler
Browse files Browse the repository at this point in the history
  • Loading branch information
petruki committed Jun 30, 2024
1 parent 92c48d3 commit c56068c
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
10 changes: 5 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,14 +43,14 @@
"express-basic-auth": "^1.2.1",
"express-rate-limit": "^7.3.1",
"express-validator": "^7.1.0",
"graphql": "^16.8.2",
"graphql": "^16.9.0",
"graphql-http": "^1.22.1",
"graphql-tag": "^2.12.6",
"helmet": "^7.1.0",
"jsonwebtoken": "^9.0.2",
"moment": "^2.30.1",
"mongodb": "^6.7.0",
"mongoose": "^8.4.3",
"mongodb": "^6.8.0",
"mongoose": "^8.4.4",
"pino": "^9.2.0",
"pino-pretty": "^11.2.1",
"swagger-ui-express": "^5.0.1",
Expand All @@ -59,11 +59,11 @@
},
"devDependencies": {
"env-cmd": "^10.1.0",
"eslint": "^9.5.0",
"eslint": "^9.6.0",
"jest": "^29.7.0",
"jest-sonar-reporter": "^2.0.0",
"node-notifier": "^10.0.1",
"nodemon": "^3.1.3",
"nodemon": "^3.1.4",
"sinon": "^18.0.0",
"supertest": "^7.0.0"
},
Expand Down
4 changes: 4 additions & 0 deletions src/middleware/auth.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@ export async function appAuth(req, res, next) {
req.rate_limit = decoded.rate_limit;
next();
} catch (err) {
if (err.name === 'TokenExpiredError') {
return res.status(401).send({ error: 'Token expired.' });
}

responseExceptionSilent(res, err, 401, 'Invalid API token.');
}
}
Expand Down

0 comments on commit c56068c

Please sign in to comment.