From b6729d8b82d9ceb7988006e3a5c28fdcf56e29ea Mon Sep 17 00:00:00 2001 From: Agusti Fernandez Pardo Date: Wed, 22 Jun 2022 05:49:24 +0200 Subject: [PATCH] fix custom prisma works --- lib/helpers/customPrisma.ts | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/lib/helpers/customPrisma.ts b/lib/helpers/customPrisma.ts index f9da8ebe1e..5082de68da 100644 --- a/lib/helpers/customPrisma.ts +++ b/lib/helpers/customPrisma.ts @@ -5,6 +5,7 @@ import { NextMiddleware } from "next-api-middleware"; import { PRISMA_CLIENT_CACHING_TIME } from "@calcom/api/lib/constants"; // import prismaAdmin from "@calcom/console/modules/common/utils/prisma"; import { asStringOrUndefined } from "@calcom/lib/asStringOrNull"; +import { CONSOLE_URL } from "@calcom/lib/constants"; import { prisma, customPrisma } from "@calcom/prisma"; // This replaces the prisma client for the cusotm one if the key is valid @@ -23,16 +24,12 @@ export const customPrismaClient: NextMiddleware = async (req, res, next) => { // const deployment = await prismaAdmin.deployment.findUnique({ // where: { key }, // }); - const databaseUrl = await fetch(`https://console.cal.com/api/deployments/database?key=${id}`) + const databaseUrl = await fetch( + `${process.env.NEXT_PUBLIC_CONSOLE_URL || CONSOLE_URL}/api/deployments/database?key=${id}` + ) .then((res) => res.json()) .then((res) => res.databaseUrl); - console.log(databaseUrl); - // if (!databaseUrl) { - // res.status(400).json({ error: "Invalid custom credentials id" }); - // return; - // } - // const credentials = deployment.databaseUrl; if (!databaseUrl) { res.status(400).json({ error: "no databaseUrl set up at your instance yet" }); return; @@ -48,7 +45,7 @@ export const customPrismaClient: NextMiddleware = async (req, res, next) => { PRISMA_CLIENT_CACHING_TIME // Cache the prisma client for 24 hours ); } - req.prisma = cachedPrisma; + req.prisma = customPrisma({ datasources: { db: { url: databaseUrl } } }); } await next(); };