fix: dont replace cal_

pull/9078/head
Agusti Fernandez Pardo 2022-05-18 21:48:13 +02:00
parent 780fd401db
commit 27053e7c80
1 changed files with 1 additions and 4 deletions

View File

@ -23,10 +23,7 @@ export const dateNotInPast = function (date: Date) {
export const verifyApiKey: NextMiddleware = async (req, res, next) => {
if (!req.query.apiKey) return res.status(401).json({ message: "No apiKey provided" });
// We remove the prefix from the user provided api_key. If no env set default to "cal_"
let strippedApiKey = `${req.query.apiKey}`.replace(process.env.API_KEY_PREFIX, "");
strippedApiKey = strippedApiKey.includes("cal_")
? strippedApiKey.replace("cal_", "")
: strippedApiKey;
const strippedApiKey = `${req.query.apiKey}`.replace(process.env.API_KEY_PREFIX || "cal_", "");
// Hash the key again before matching against the database records.
const hashedKey = hashAPIKey(strippedApiKey);
// Check if the hashed api key exists in database.