feat(auth): add verbose logging for API key extraction
All checks were successful
Auto Changelog & Release / detect-version-change (push) Successful in 4s
Auto Changelog & Release / release (push) Has been skipped
Auto Changelog & Release / changelog-only (push) Successful in 8s
Build and upload Docker nightly image / build-and-push (push) Successful in 2m20s
All checks were successful
Auto Changelog & Release / detect-version-change (push) Successful in 4s
Auto Changelog & Release / release (push) Has been skipped
Auto Changelog & Release / changelog-only (push) Successful in 8s
Build and upload Docker nightly image / build-and-push (push) Successful in 2m20s
- Improve debugging by logging the provided and extracted API keys when verbose mode is enabled in the environment configuration.
This commit is contained in:
@@ -8,9 +8,17 @@ import { Env } from './env.ts';
|
||||
export const authMiddleware: Middleware = async (ctx, next) => {
|
||||
const key = ctx.query.apiKey;
|
||||
|
||||
if (Env.verbose) {
|
||||
console.debug('API key:', key);
|
||||
}
|
||||
|
||||
// Support both ?apiKey=... and form body with apiKey=...
|
||||
const extractedKey = Array.isArray(key) ? key[0] : key;
|
||||
|
||||
if (Env.verbose) {
|
||||
console.debug('Extracted API key:', extractedKey);
|
||||
}
|
||||
|
||||
if (!extractedKey || !Env.apiKeys.includes(extractedKey)) {
|
||||
return new Response('Forbidden – Invalid API key', { status: 403 });
|
||||
}
|
||||
|
Reference in New Issue
Block a user