(req: NextRequest)
| 25 | * Extract api key from x-codebuff-api-key header or authorization header |
| 26 | */ |
| 27 | export function extractApiKeyFromHeader(req: NextRequest): string | undefined { |
| 28 | const token = req.headers.get('x-codebuff-api-key') |
| 29 | if (typeof token === 'string' && token) { |
| 30 | return token |
| 31 | } |
| 32 | |
| 33 | const authorization = req.headers.get('Authorization') |
| 34 | if (!authorization) { |
| 35 | return undefined |
| 36 | } |
| 37 | if (!authorization.startsWith('Bearer ')) { |
| 38 | return undefined |
| 39 | } |
| 40 | return authorization.slice('Bearer '.length) |
| 41 | } |
no test coverage detected