Reformat all project files to use the prettier config file.
This commit is contained in:
@@ -9,12 +9,12 @@ const path = require("path");
|
||||
* @param next
|
||||
*/
|
||||
function eventAuthorizationMiddleware(req, res, next) {
|
||||
if (req.headers["event-secret"] !== process.env.EVENT_SECRET) {
|
||||
return res.status(401).send("Unauthorized");
|
||||
}
|
||||
if (req.headers["event-secret"] !== process.env.EVENT_SECRET) {
|
||||
return res.status(401).send("Unauthorized");
|
||||
}
|
||||
|
||||
req.isEventAuthorized = true;
|
||||
next();
|
||||
req.isEventAuthorized = true;
|
||||
next();
|
||||
}
|
||||
|
||||
module.exports = eventAuthorizationMiddleware;
|
||||
module.exports = eventAuthorizationMiddleware;
|
||||
|
||||
@@ -11,16 +11,16 @@ const adminEmail = require("../utils/adminEmail");
|
||||
* @returns {*}
|
||||
*/
|
||||
const validateAdminMiddleware = (req, res, next) => {
|
||||
if (!adminEmail.includes(req.user.email) && !req.user.ioadmin) {
|
||||
logger.log("admin-validation-failed", "ERROR", req.user.email, null, {
|
||||
request: req.body,
|
||||
user: req.user,
|
||||
});
|
||||
return res.sendStatus(404);
|
||||
}
|
||||
if (!adminEmail.includes(req.user.email) && !req.user.ioadmin) {
|
||||
logger.log("admin-validation-failed", "ERROR", req.user.email, null, {
|
||||
request: req.body,
|
||||
user: req.user
|
||||
});
|
||||
return res.sendStatus(404);
|
||||
}
|
||||
|
||||
req.isAdmin = true;
|
||||
next();
|
||||
req.isAdmin = true;
|
||||
next();
|
||||
};
|
||||
|
||||
module.exports = validateAdminMiddleware;
|
||||
module.exports = validateAdminMiddleware;
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
const {GraphQLClient} = require("graphql-request");
|
||||
const { GraphQLClient } = require("graphql-request");
|
||||
|
||||
/**
|
||||
* Middleware to add a GraphQL Client to the request object
|
||||
@@ -10,15 +10,15 @@ const {GraphQLClient} = require("graphql-request");
|
||||
* @param next
|
||||
*/
|
||||
const withUserGraphQLClientMiddleware = (req, res, next) => {
|
||||
const BearerToken = req.headers.authorization;
|
||||
req.userGraphQLClient = new GraphQLClient(process.env.GRAPHQL_ENDPOINT, {
|
||||
headers: {
|
||||
Authorization: BearerToken,
|
||||
},
|
||||
});
|
||||
req.BearerToken = BearerToken;
|
||||
const BearerToken = req.headers.authorization;
|
||||
req.userGraphQLClient = new GraphQLClient(process.env.GRAPHQL_ENDPOINT, {
|
||||
headers: {
|
||||
Authorization: BearerToken
|
||||
}
|
||||
});
|
||||
req.BearerToken = BearerToken;
|
||||
|
||||
next();
|
||||
next();
|
||||
};
|
||||
|
||||
module.exports = withUserGraphQLClientMiddleware;
|
||||
module.exports = withUserGraphQLClientMiddleware;
|
||||
|
||||
Reference in New Issue
Block a user