From d280bcadf39a638db92b83a3ef64cbbe94135ffa Mon Sep 17 00:00:00 2001 From: Eric Ciarla Date: Tue, 7 May 2024 13:52:42 -0400 Subject: [PATCH] Add keyAuth --- apps/api/src/controllers/keyAuth.ts | 24 ++++++++++++++++++++++++ apps/api/src/routes/v0.ts | 4 ++++ 2 files changed, 28 insertions(+) create mode 100644 apps/api/src/controllers/keyAuth.ts diff --git a/apps/api/src/controllers/keyAuth.ts b/apps/api/src/controllers/keyAuth.ts new file mode 100644 index 0000000..351edd1 --- /dev/null +++ b/apps/api/src/controllers/keyAuth.ts @@ -0,0 +1,24 @@ + +import { AuthResponse, RateLimiterMode } from "../types"; + +import { Request, Response } from "express"; +import { authenticateUser } from "./auth"; + + +export const keyAuthController = async (req: Request, res: Response) => { + try { + // make sure to authenticate user first, Bearer + const { success, team_id, error, status } = await authenticateUser( + req, + res + ); + if (!success) { + return res.status(status).json({ error }); + } + // if success, return success: true + return res.status(200).json({ success: true }); + } catch (error) { + return res.status(500).json({ error: error.message }); + } +}; + diff --git a/apps/api/src/routes/v0.ts b/apps/api/src/routes/v0.ts index 42b8814..a9a3a9b 100644 --- a/apps/api/src/routes/v0.ts +++ b/apps/api/src/routes/v0.ts @@ -6,6 +6,7 @@ import { crawlPreviewController } from "../../src/controllers/crawlPreview"; import { crawlJobStatusPreviewController } from "../../src/controllers/status"; import { searchController } from "../../src/controllers/search"; import { crawlCancelController } from "../../src/controllers/crawl-cancel"; +import { keyAuthController } from "../../src/controllers/keyAuth"; export const v0Router = express.Router(); @@ -16,6 +17,9 @@ v0Router.get("/v0/crawl/status/:jobId", crawlStatusController); v0Router.delete("/v0/crawl/cancel/:jobId", crawlCancelController); v0Router.get("/v0/checkJobStatus/:jobId", crawlJobStatusPreviewController); +// Auth route for key based authentication +v0Router.get("/v0/keyAuth", keyAuthController); + // Search routes v0Router.post("/v0/search", searchController);