Merge pull request #37 from calcom/ignore-api-key-in-docs
commit
e3f9c91a5c
|
@ -13,11 +13,12 @@ const today = new Date();
|
||||||
|
|
||||||
// This verifies the API key and sets the user if it is valid.
|
// This verifies the API key and sets the user if it is valid.
|
||||||
export const verifyApiKey: NextMiddleware = async (req, res, next) => {
|
export const verifyApiKey: NextMiddleware = async (req, res, next) => {
|
||||||
|
const pathIsDocs = req.url?.startsWith("/docs");
|
||||||
|
if (pathIsDocs) await next();
|
||||||
if (!req.query.apiKey) res.status(401).json({ message: "No API key provided" });
|
if (!req.query.apiKey) res.status(401).json({ message: "No API key provided" });
|
||||||
|
|
||||||
const strippedApiKey = `${req.query.apiKey}`.replace(process.env.API_KEY_PREFIX || "cal_", "");
|
const strippedApiKey = `${req.query.apiKey}`.replace(process.env.API_KEY_PREFIX || "cal_", "");
|
||||||
const hashedKey = hashAPIKey(strippedApiKey);
|
const hashedKey = hashAPIKey(strippedApiKey);
|
||||||
|
|
||||||
await prisma.apiKey
|
await prisma.apiKey
|
||||||
.findUnique({ where: { hashedKey } })
|
.findUnique({ where: { hashedKey } })
|
||||||
.then(async (apiKey) => {
|
.then(async (apiKey) => {
|
||||||
|
|
Loading…
Reference in New Issue