Skip to content

Supercharge your AI agents with data from the web and beyond. Building the library for superintelligence. 🔥

fix(v1/crawl-cancel): avoid double authing

Gergő Móricz3e661a20872d
diff --git a/apps/api/src/controllers/v1/crawl-cancel.ts b/apps/api/src/controllers/v1/crawl-cancel.ts
index 21fc7cf9c..f8fba824a 100644
--- a/apps/api/src/controllers/v1/crawl-cancel.ts
+++ b/apps/api/src/controllers/v1/crawl-cancel.ts
@@ -1,26 +1,16 @@
-import { Request, Response } from "express";
-import { authenticateUser } from "../auth";
-import { RateLimiterMode } from "../../types";
+import { Response } from "express";
import { supabase_service } from "../../services/supabase";
import { Logger } from "../../lib/logger";
import { getCrawl, saveCrawl } from "../../lib/crawl-redis";
import * as Sentry from "@sentry/node";
import { configDotenv } from "dotenv";
+import { RequestWithAuth } from "./types";
configDotenv();
-export async function crawlCancelController(req: Request, res: Response) {
+export async function crawlCancelController(req: RequestWithAuth<{ jobId: string }>, res: Response) {
try {
const useDbAuthentication = process.env.USE_DB_AUTHENTICATION === 'true';
- const { success, team_id, error, status } = await authenticateUser(
- req,
- res,
- RateLimiterMode.CrawlStatus
- );
- if (!success) {
- return res.status(status).json({ error });
- }
-
const sc = await getCrawl(req.params.jobId);
if (!sc) {
return res.status(404).json({ error: "Job not found" });
@@ -32,7 +22,7 @@ export async function crawlCancelController(req: Request, res: Response) {
.from("bulljobs_teams")
.select("*")
.eq("job_id", req.params.jobId)
- .eq("team_id", team_id);
+ .eq("team_id", req.auth.team_id);
if (supaError) {
return res.status(500).json({ error: supaError.message });
}
diff --git a/apps/api/src/routes/v1.ts b/apps/api/src/routes/v1.ts
index 484ab5dc4..b827e8632 100644
--- a/apps/api/src/routes/v1.ts
+++ b/apps/api/src/routes/v1.ts
@@ -148,7 +148,7 @@ v1Router.ws(
v1Router.delete(
"/crawl/:jobId",
- authMiddleware(RateLimiterMode.Crawl),
+ authMiddleware(RateLimiterMode.CrawlStatus),
crawlCancelController
);
// v1Router.get("/checkJobStatus/:jobId", crawlJobStatusPreviewController);