feat: add bot-secret auth helper for /api/bot/* routes

Co-Authored-By: Claude Sonnet 5 <[email protected]>
This commit is contained in:
toanhoang
2026-08-19 22:07:07 -04:00
co-authored by Claude Sonnet 5
parent 8a02a7c7ef
commit d5a0f1cb74
+12
View File
@@ -0,0 +1,12 @@
// Shared-secret auth for the /api/bot/* routes — the inventory-capture
// Telegram bot (a separate Python service, not a browser) calls these, so
// it can't go through the Auth.js session/cookie flow the rest of the app
// uses (src/auth.ts). Deliberately a SEPARATE secret from AUTH_SECRET
// (session JWT signing key) and from the review-page User account's
// password — a machine credential, not a human one, so it can be rotated
// independently without touching either.
export function requireBotAuth(request: Request): boolean {
const header = request.headers.get("authorization") ?? "";
const expected = `Bearer ${process.env.BOT_INGEST_SECRET}`;
return Boolean(process.env.BOT_INGEST_SECRET) && header === expected;
}