From 61f39b64b9c1dfaa937d912a371509297e87866e Mon Sep 17 00:00:00 2001 From: Miodec Date: Fri, 4 Feb 2022 13:06:09 +0100 Subject: [PATCH] handling one possible exception --- backend/middlewares/auth.js | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/backend/middlewares/auth.js b/backend/middlewares/auth.js index 62807527f..d46862613 100644 --- a/backend/middlewares/auth.js +++ b/backend/middlewares/auth.js @@ -30,7 +30,15 @@ module.exports = { return next( new MonkeyError(400, "Invalid Token", "Incorrect token type") ); - req.decodedToken = await verifyIdToken(token[1]); + try { + req.decodedToken = await verifyIdToken(token[1]); + } catch (err) { + if (err.message == "auth/id-token-expired") { + new MonkeyError(401, "Unauthorized", "Token expired"); + } else { + throw err; + } + } return next(); } catch (e) { return next(e);