Reformat all project files to use the prettier config file.
This commit is contained in:
@@ -12,58 +12,51 @@ const admin = require("firebase-admin");
|
||||
* @returns {Promise<void>}
|
||||
*/
|
||||
const validateFirebaseIdTokenMiddleware = async (req, res, next) => {
|
||||
if (
|
||||
(
|
||||
!req.headers.authorization ||
|
||||
!req.headers.authorization.startsWith("Bearer ")) &&
|
||||
!(req.cookies && req.cookies.__session
|
||||
)
|
||||
) {
|
||||
console.error("Unauthorized attempt. No authorization provided.");
|
||||
return res.status(403).send("Unauthorized");
|
||||
}
|
||||
if (
|
||||
(!req.headers.authorization || !req.headers.authorization.startsWith("Bearer ")) &&
|
||||
!(req.cookies && req.cookies.__session)
|
||||
) {
|
||||
console.error("Unauthorized attempt. No authorization provided.");
|
||||
return res.status(403).send("Unauthorized");
|
||||
}
|
||||
|
||||
let idToken;
|
||||
let idToken;
|
||||
|
||||
if (
|
||||
req.headers.authorization &&
|
||||
req.headers.authorization.startsWith("Bearer ")
|
||||
) {
|
||||
// console.log('Found "Authorization" header');
|
||||
// Read the ID Token from the Authorization header.
|
||||
idToken = req.headers.authorization.split("Bearer ")[1];
|
||||
} else if (req.cookies) {
|
||||
//console.log('Found "__session" cookie');
|
||||
// Read the ID Token from cookie.
|
||||
idToken = req.cookies.__session;
|
||||
} else {
|
||||
// No cookie
|
||||
console.error("Unauthorized attempt. No cookie provided.");
|
||||
logger.log("api-unauthorized-call", "WARN", null, null, {
|
||||
req,
|
||||
type: "no-cookie",
|
||||
});
|
||||
if (req.headers.authorization && req.headers.authorization.startsWith("Bearer ")) {
|
||||
// console.log('Found "Authorization" header');
|
||||
// Read the ID Token from the Authorization header.
|
||||
idToken = req.headers.authorization.split("Bearer ")[1];
|
||||
} else if (req.cookies) {
|
||||
//console.log('Found "__session" cookie');
|
||||
// Read the ID Token from cookie.
|
||||
idToken = req.cookies.__session;
|
||||
} else {
|
||||
// No cookie
|
||||
console.error("Unauthorized attempt. No cookie provided.");
|
||||
logger.log("api-unauthorized-call", "WARN", null, null, {
|
||||
req,
|
||||
type: "no-cookie"
|
||||
});
|
||||
|
||||
return res.status(403).send("Unauthorized");
|
||||
}
|
||||
return res.status(403).send("Unauthorized");
|
||||
}
|
||||
|
||||
try {
|
||||
const decodedIdToken = await admin.auth().verifyIdToken(idToken);
|
||||
//console.log("ID Token correctly decoded", decodedIdToken);
|
||||
req.user = decodedIdToken;
|
||||
next();
|
||||
try {
|
||||
const decodedIdToken = await admin.auth().verifyIdToken(idToken);
|
||||
//console.log("ID Token correctly decoded", decodedIdToken);
|
||||
req.user = decodedIdToken;
|
||||
next();
|
||||
} catch (error) {
|
||||
logger.log("api-unauthorized-call", "WARN", null, null, {
|
||||
path: req.path,
|
||||
body: req.body,
|
||||
|
||||
} catch (error) {
|
||||
logger.log("api-unauthorized-call", "WARN", null, null, {
|
||||
path: req.path,
|
||||
body: req.body,
|
||||
type: "unauthroized",
|
||||
...error
|
||||
});
|
||||
|
||||
type: "unauthroized",
|
||||
...error,
|
||||
});
|
||||
|
||||
return res.status(401).send("Unauthorized");
|
||||
}
|
||||
return res.status(401).send("Unauthorized");
|
||||
}
|
||||
};
|
||||
|
||||
module.exports = validateFirebaseIdTokenMiddleware;
|
||||
module.exports = validateFirebaseIdTokenMiddleware;
|
||||
|
||||
Reference in New Issue
Block a user