From a2ae5f81d92a102ba009f090054161233d452018 Mon Sep 17 00:00:00 2001 From: Stefan Terdell Date: Sun, 7 Jul 2024 15:06:31 +0200 Subject: [PATCH] Only check Supabase if configured to --- apps/api/src/controllers/crawl-cancel.ts | 25 ++++++++++++++---------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/apps/api/src/controllers/crawl-cancel.ts b/apps/api/src/controllers/crawl-cancel.ts index 8e8ba313..160824ff 100644 --- a/apps/api/src/controllers/crawl-cancel.ts +++ b/apps/api/src/controllers/crawl-cancel.ts @@ -8,6 +8,8 @@ import { billTeam } from "../../src/services/billing/credit_billing"; export async function crawlCancelController(req: Request, res: Response) { try { + const useDbAuthentication = process.env.USE_DB_AUTHENTICATION === 'true'; + const { success, team_id, error, status } = await authenticateUser( req, res, @@ -22,18 +24,21 @@ export async function crawlCancelController(req: Request, res: Response) { } // check if the job belongs to the team - const { data, error: supaError } = await supabase_service - .from("bulljobs_teams") - .select("*") - .eq("job_id", req.params.jobId) - .eq("team_id", team_id); - if (supaError) { - return res.status(500).json({ error: supaError.message }); + if (useDbAuthentication) { + const { data, error: supaError } = await supabase_service + .from("bulljobs_teams") + .select("*") + .eq("job_id", req.params.jobId) + .eq("team_id", team_id); + if (supaError) { + return res.status(500).json({ error: supaError.message }); + } + + if (data.length === 0) { + return res.status(403).json({ error: "Unauthorized" }); + } } - if (data.length === 0) { - return res.status(403).json({ error: "Unauthorized" }); - } const jobState = await job.getState(); const { partialDocs } = await job.progress();