only approve zapier api key
parent
0f25d31361
commit
831c85dfef
|
@ -4,6 +4,7 @@ import { v4 } from "uuid";
|
|||
|
||||
import findValidApiKey from "@calcom/ee/lib/api/findValidApiKey";
|
||||
import prisma from "@calcom/prisma";
|
||||
import { ApiKeyType } from "@prisma/client";
|
||||
|
||||
export default async function handler(req: NextApiRequest, res: NextApiResponse) {
|
||||
const apiKey = req.query.apiKey as string;
|
||||
|
@ -12,7 +13,7 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse)
|
|||
return res.status(401).json({ message: "No API key provided" });
|
||||
}
|
||||
|
||||
const validKey = await findValidApiKey(apiKey);
|
||||
const validKey = await findValidApiKey(apiKey, ApiKeyType.ZAPIER);
|
||||
|
||||
if (!validKey) {
|
||||
return res.status(401).json({ message: "API key not valid" });
|
||||
|
|
|
@ -2,6 +2,7 @@ import type { NextApiRequest, NextApiResponse } from "next";
|
|||
|
||||
import findValidApiKey from "@calcom/ee/lib/api/findValidApiKey";
|
||||
import prisma from "@calcom/prisma";
|
||||
import { ApiKeyType } from "@prisma/client";
|
||||
|
||||
export default async function handler(req: NextApiRequest, res: NextApiResponse) {
|
||||
const apiKey = req.query.apiKey as string;
|
||||
|
@ -10,7 +11,7 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse)
|
|||
return res.status(401).json({ message: "No API key provided" });
|
||||
}
|
||||
|
||||
const validKey = await findValidApiKey(apiKey);
|
||||
const validKey = await findValidApiKey(apiKey, ApiKeyType.ZAPIER);
|
||||
|
||||
if (!validKey) {
|
||||
return res.status(401).json({ message: "API not valid" });
|
||||
|
|
|
@ -2,6 +2,7 @@ import type { NextApiRequest, NextApiResponse } from "next";
|
|||
|
||||
import findValidApiKey from "@calcom/ee/lib/api/findValidApiKey";
|
||||
import prisma from "@calcom/prisma";
|
||||
import { ApiKeyType } from "@prisma/client";
|
||||
|
||||
export default async function handler(req: NextApiRequest, res: NextApiResponse) {
|
||||
const apiKey = req.query.apiKey as string;
|
||||
|
@ -10,7 +11,7 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse)
|
|||
return res.status(401).json({ message: "No API key provided" });
|
||||
}
|
||||
|
||||
const validKey = await findValidApiKey(apiKey);
|
||||
const validKey = await findValidApiKey(apiKey, ApiKeyType.ZAPIER);
|
||||
|
||||
if (!validKey) {
|
||||
return res.status(401).json({ message: "API not valid" });
|
||||
|
|
|
@ -1,22 +1,27 @@
|
|||
import { hashAPIKey } from "@calcom/ee/lib/api/apiKeys";
|
||||
import prisma from "@calcom/prisma";
|
||||
import { ApiKeyType } from "@prisma/client";
|
||||
|
||||
const findValidApiKey = async (apiKey: string) => {
|
||||
const findValidApiKey = async (apiKey: string, apiKeyType: ApiKeyType) => {
|
||||
const hashedKey = hashAPIKey(apiKey.substring(process.env.API_KEY_PREFIX?.length || 0));
|
||||
|
||||
const validKey = await prisma.apiKey.findFirst({
|
||||
where: {
|
||||
AND: [
|
||||
{
|
||||
hashedKey,
|
||||
},
|
||||
{
|
||||
expiresAt: {
|
||||
gte: new Date(Date.now()),
|
||||
where: {
|
||||
AND: [
|
||||
{
|
||||
hashedKey,
|
||||
},
|
||||
},
|
||||
],
|
||||
},
|
||||
});
|
||||
{
|
||||
expiresAt: {
|
||||
gte: new Date(Date.now()),
|
||||
},
|
||||
},
|
||||
{
|
||||
apiKeyType,
|
||||
},
|
||||
],
|
||||
},
|
||||
});
|
||||
|
||||
return validKey;
|
||||
};
|
||||
|
|
Loading…
Reference in New Issue