mirror of
https://github.com/monkeytypegame/monkeytype.git
synced 2024-11-10 17:04:49 +08:00
checking if token wasnt revoked
added error if token was revoked fixed token errors
This commit is contained in:
parent
5bd0c854e8
commit
c7a200b476
2 changed files with 17 additions and 3 deletions
|
@ -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, {
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue