From 3d917e4dd486453da56d6241b308fab9c98a73c2 Mon Sep 17 00:00:00 2001 From: Agusti Fernandez Pardo Date: Fri, 8 Apr 2022 01:59:04 +0200 Subject: [PATCH] make verifyApiKey check for hashed, need @calcom/ee in transpile modules next.config --- lib/helpers/verifyApiKey.ts | 5 ++++- next.config.js | 2 +- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/lib/helpers/verifyApiKey.ts b/lib/helpers/verifyApiKey.ts index 740c4a2de4..275457d12c 100644 --- a/lib/helpers/verifyApiKey.ts +++ b/lib/helpers/verifyApiKey.ts @@ -1,5 +1,6 @@ import { NextMiddleware } from "next-api-middleware"; +import { hashAPIKey } from "@calcom/ee/lib/api/apiKeys"; // import { nanoid } from "nanoid"; import prisma from "@calcom/prisma"; @@ -12,7 +13,9 @@ const today = new Date(); export const verifyApiKey: NextMiddleware = async (req, res, next) => { if (!req.query.apiKey) res.status(401).json({ message: "No API key provided" }); - const apiKey = await prisma.apiKey.findUnique({ where: { id: req.query.apiKey as string } }); + const strippedApiKey = `${req.query.apiKey}`.replace("cal_", ""); + const hashedKey = hashAPIKey(strippedApiKey); + const apiKey = await prisma.apiKey.findUnique({ where: { hashedKey } }); if (!apiKey) { res.status(401).json({ error: "Your api key is not valid" }); throw new Error("No api key found"); diff --git a/next.config.js b/next.config.js index 1962fe9a8e..c6f75ad063 100644 --- a/next.config.js +++ b/next.config.js @@ -1,6 +1,6 @@ // https://www.npmjs.com/package/next-transpile-modules // This makes our @calcom/prisma package from the monorepo to be transpiled and usable by API -const withTM = require("next-transpile-modules")(["@calcom/prisma", "@calcom/lib"]); +const withTM = require("next-transpile-modules")(["@calcom/prisma", "@calcom/lib", "@calcom/ee"]); // use something like withPlugins([withTM], {}) if more plugins added later.