Merge pull request #131 from mendableai/feat/key-auth
Add keyAuth endpoint
This commit is contained in:
commit
6956e5016d
24
apps/api/src/controllers/keyAuth.ts
Normal file
24
apps/api/src/controllers/keyAuth.ts
Normal 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 });
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
@ -6,6 +6,7 @@ import { crawlPreviewController } from "../../src/controllers/crawlPreview";
|
|||||||
import { crawlJobStatusPreviewController } from "../../src/controllers/status";
|
import { crawlJobStatusPreviewController } from "../../src/controllers/status";
|
||||||
import { searchController } from "../../src/controllers/search";
|
import { searchController } from "../../src/controllers/search";
|
||||||
import { crawlCancelController } from "../../src/controllers/crawl-cancel";
|
import { crawlCancelController } from "../../src/controllers/crawl-cancel";
|
||||||
|
import { keyAuthController } from "../../src/controllers/keyAuth";
|
||||||
|
|
||||||
export const v0Router = express.Router();
|
export const v0Router = express.Router();
|
||||||
|
|
||||||
@ -16,6 +17,9 @@ v0Router.get("/v0/crawl/status/:jobId", crawlStatusController);
|
|||||||
v0Router.delete("/v0/crawl/cancel/:jobId", crawlCancelController);
|
v0Router.delete("/v0/crawl/cancel/:jobId", crawlCancelController);
|
||||||
v0Router.get("/v0/checkJobStatus/:jobId", crawlJobStatusPreviewController);
|
v0Router.get("/v0/checkJobStatus/:jobId", crawlJobStatusPreviewController);
|
||||||
|
|
||||||
|
// Auth route for key based authentication
|
||||||
|
v0Router.get("/v0/keyAuth", keyAuthController);
|
||||||
|
|
||||||
// Search routes
|
// Search routes
|
||||||
v0Router.post("/v0/search", searchController);
|
v0Router.post("/v0/search", searchController);
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user