Fix: credential sync app lookup
parent
a3a49f9069
commit
62b3b87cda
|
@ -15,12 +15,10 @@ const appCredentialWebhookRequestBodySchema = z.object({
|
||||||
});
|
});
|
||||||
/** */
|
/** */
|
||||||
export default async function handler(req: NextApiRequest, res: NextApiResponse) {
|
export default async function handler(req: NextApiRequest, res: NextApiResponse) {
|
||||||
// Check that credential sharing is enabled
|
|
||||||
if (!APP_CREDENTIAL_SHARING_ENABLED) {
|
if (!APP_CREDENTIAL_SHARING_ENABLED) {
|
||||||
return res.status(403).json({ message: "Credential sharing is not enabled" });
|
return res.status(403).json({ message: "Credential sharing is not enabled" });
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check that the webhook secret matches
|
|
||||||
if (
|
if (
|
||||||
req.headers[process.env.CALCOM_WEBHOOK_HEADER_NAME || "calcom-webhook-secret"] !==
|
req.headers[process.env.CALCOM_WEBHOOK_HEADER_NAME || "calcom-webhook-secret"] !==
|
||||||
process.env.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);
|
const reqBody = appCredentialWebhookRequestBodySchema.parse(req.body);
|
||||||
|
|
||||||
// Check that the user exists
|
|
||||||
const user = await prisma.user.findUnique({ where: { id: reqBody.userId } });
|
const user = await prisma.user.findUnique({ where: { id: reqBody.userId } });
|
||||||
|
|
||||||
if (!user) {
|
if (!user) {
|
||||||
|
@ -46,19 +43,17 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse)
|
||||||
return res.status(404).json({ message: "App not found" });
|
return res.status(404).json({ message: "App not found" });
|
||||||
}
|
}
|
||||||
|
|
||||||
// Search for the app's slug and type
|
const appMetadata = appStoreMetadata[app.dirName as keyof typeof appStoreMetadata];
|
||||||
const appMetadata = appStoreMetadata[app.slug as keyof typeof appStoreMetadata];
|
|
||||||
|
|
||||||
if (!appMetadata) {
|
if (!appMetadata) {
|
||||||
return res.status(404).json({ message: "App not found. Ensure that you have the correct app slug" });
|
return res.status(404).json({ message: "App not found. Ensure that you have the correct app slug" });
|
||||||
}
|
}
|
||||||
|
|
||||||
// Decrypt the keys
|
|
||||||
const keys = JSON.parse(
|
const keys = JSON.parse(
|
||||||
symmetricDecrypt(reqBody.keys, process.env.CALCOM_APP_CREDENTIAL_ENCRYPTION_KEY || "")
|
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({
|
const appCredential = await prisma.credential.findFirst({
|
||||||
where: {
|
where: {
|
||||||
userId: reqBody.userId,
|
userId: reqBody.userId,
|
||||||
|
|
Loading…
Reference in New Issue