CognxSafeTrack
Claude Sonnet 4.6
fix(auth): validateApiKey accepts Bearer pattern used by worker
c5813d5 Download apps/api/src/middleware/validateApiKey.ts from safetrack/edtech: direct link, hf CLI and curl.
- Browser
- Download file 582 Bytes
-
https://huggingface.co/spaces/safetrack/edtech/resolve/main/apps/api/src/middleware/validateApiKey.ts
- Command line
-
hf download hf://spaces/safetrack/edtech/apps/api/src/middleware/validateApiKey.ts
-
curl -L -o validateApiKey.ts https://huggingface.co/spaces/safetrack/edtech/resolve/main/apps/api/src/middleware/validateApiKey.ts
582 Bytes
| import { FastifyRequest } from 'fastify'; | |
| /** | |
| * Accepts two patterns: | |
| * 1. x-api-key: ADMIN_API_KEY (direct header) | |
| * 2. Authorization: Bearer ADMIN_API_KEY (worker internal calls via api-client.ts) | |
| */ | |
| export const validateApiKey = async (request: FastifyRequest): Promise<boolean> => { | |
| const apiKey = process.env.ADMIN_API_KEY; | |
| if (!apiKey) return false; | |
| if (request.headers['x-api-key'] === apiKey) return true; | |
| const authHeader = request.headers['authorization']; | |
| if (authHeader === `Bearer ${apiKey}`) return true; | |
| return false; | |
| }; | |