diff --git a/backend/handlers/auth.js b/backend/handlers/auth.js index 9cc4f89a3..466650099 100644 --- a/backend/handlers/auth.js +++ b/backend/handlers/auth.js @@ -2,7 +2,7 @@ const admin = require("firebase-admin"); module.exports = { async verifyIdToken(idToken) { - return await admin.auth().verifyIdToken(idToken); + return await admin.auth().verifyIdToken(idToken, true); }, async updateAuthEmail(uid, email) { return await admin.auth().updateUser(uid, { diff --git a/backend/middlewares/auth.js b/backend/middlewares/auth.js index 67328b6f3..9d99f783a 100644 --- a/backend/middlewares/auth.js +++ b/backend/middlewares/auth.js @@ -70,8 +70,22 @@ async function authenticateWithBearerToken(token) { try { return await verifyIdToken(token); } catch (error) { - if (error.message.includes("auth/id-token-expired")) { - throw new MonkeyError(401, "Unauthorized", "Token expired"); + console.log("-----------"); + console.log(error.errorInfo.code); + console.log("-----------"); + + if (error?.errorInfo?.code?.includes("auth/id-token-expired")) { + throw new MonkeyError( + 401, + "Token expired. Please login again.", + "authenticateWithBearerToken" + ); + } else if (error?.errorInfo?.code?.includes("auth/id-token-revoked")) { + throw new MonkeyError( + 401, + "Token revoked. Please login again.", + "authenticateWithBearerToken" + ); } else { throw error; }