From 62b3b87cda873b04725e669ddae7f56b89c2cddc Mon Sep 17 00:00:00 2001 From: Keith Williams Date: Tue, 26 Sep 2023 07:04:51 -0300 Subject: [PATCH] Fix: credential sync app lookup --- apps/web/pages/api/webhook/app-credential.ts | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/apps/web/pages/api/webhook/app-credential.ts b/apps/web/pages/api/webhook/app-credential.ts index 326cfb5b4d..8034768bb3 100644 --- a/apps/web/pages/api/webhook/app-credential.ts +++ b/apps/web/pages/api/webhook/app-credential.ts @@ -15,12 +15,10 @@ const appCredentialWebhookRequestBodySchema = z.object({ }); /** */ export default async function handler(req: NextApiRequest, res: NextApiResponse) { - // Check that credential sharing is enabled if (!APP_CREDENTIAL_SHARING_ENABLED) { return res.status(403).json({ message: "Credential sharing is not enabled" }); } - // Check that the webhook secret matches if ( req.headers[process.env.CALCOM_WEBHOOK_HEADER_NAME || "calcom-webhook-secret"] !== process.env.CALCOM_WEBHOOK_SECRET @@ -30,7 +28,6 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse) const reqBody = appCredentialWebhookRequestBodySchema.parse(req.body); - // Check that the user exists const user = await prisma.user.findUnique({ where: { id: reqBody.userId } }); if (!user) { @@ -46,19 +43,17 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse) return res.status(404).json({ message: "App not found" }); } - // Search for the app's slug and type - const appMetadata = appStoreMetadata[app.slug as keyof typeof appStoreMetadata]; + const appMetadata = appStoreMetadata[app.dirName as keyof typeof appStoreMetadata]; if (!appMetadata) { return res.status(404).json({ message: "App not found. Ensure that you have the correct app slug" }); } - // Decrypt the keys const keys = JSON.parse( symmetricDecrypt(reqBody.keys, process.env.CALCOM_APP_CREDENTIAL_ENCRYPTION_KEY || "") ); - // Can't use prisma upsert as we don't know the id of the credential + // INFO: Can't use prisma upsert as we don't know the id of the credential const appCredential = await prisma.credential.findFirst({ where: { userId: reqBody.userId,