checking if token wasnt revoked

added error if token was revoked
fixed token errors
This commit is contained in:
Miodec 2022-02-09 14:18:49 +01:00
parent 5bd0c854e8
commit c7a200b476
2 changed files with 17 additions and 3 deletions

View file

@ -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, {

View file

@ -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;
}