Skip to content

Commit 84dd096

Browse files
committed
pkg:auth:feat: add a customAPIKeyGetter in apiKey plugin
1 parent 00f9373 commit 84dd096

1 file changed

Lines changed: 13 additions & 0 deletions

File tree

packages/auth/src/configs/auth.config.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -250,6 +250,19 @@ export function createAuthConfig(env: Env) {
250250
};
251251
},
252252
},
253+
customAPIKeyGetter: (ctx) => {
254+
// First try x-api-key header
255+
const apiKeyHeader = ctx.headers?.get('x-api-key');
256+
if (apiKeyHeader) return apiKeyHeader;
257+
258+
// Then try Authorization Bearer header
259+
const authHeader = ctx.headers?.get('authorization');
260+
if (authHeader?.startsWith('Bearer ')) {
261+
return authHeader.replace('Bearer ', '');
262+
}
263+
264+
return null;
265+
},
253266
}),
254267
multiSession({
255268
maximumSessions: MAX_SESSIONS + 1, // better-auth issue: 3 is actually allowing max 2 sessions

0 commit comments

Comments
 (0)