0

Merge pull request #131 from mendableai/feat/key-auth

Add keyAuth endpoint
This commit is contained in:
Nicolas 2024-05-07 10:54:56 -07:00 committed by GitHub
commit 6956e5016d
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 28 additions and 0 deletions

View File

@ -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 <token>
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 });
}
};

View File

@ -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);