Initial import of verae-middleware from zapier monorepo
This commit is contained in:
commit
fb6db30e0e
66 changed files with 6590 additions and 0 deletions
27
src/middleware/authenticate.js
Normal file
27
src/middleware/authenticate.js
Normal file
|
|
@ -0,0 +1,27 @@
|
|||
/**
|
||||
* @fileoverview Express auth middleware — populates req.auth.
|
||||
* @module middleware/authenticate
|
||||
*/
|
||||
|
||||
import { extractBearerToken } from '../lib/tokens.js';
|
||||
import { resolveAuthContext } from '../services/authService.js';
|
||||
import { asyncHandler } from '../errors.js';
|
||||
import { createDebugger } from '../debug/logger.js';
|
||||
|
||||
const log = createDebugger('auth');
|
||||
|
||||
/**
|
||||
* Resolve Bearer or x-api-key into `req.auth`.
|
||||
*/
|
||||
export const authenticate = asyncHandler(async (req, res, next) => {
|
||||
const rawToken =
|
||||
extractBearerToken(req.headers.authorization) ?? req.headers['x-api-key'] ?? null;
|
||||
|
||||
req.auth = await resolveAuthContext(rawToken);
|
||||
log.debug('authenticated', {
|
||||
tenantId: req.auth.tenantId,
|
||||
method: req.auth.authMethod,
|
||||
plan: req.auth.tenant?.plan,
|
||||
});
|
||||
next();
|
||||
});
|
||||
Loading…
Add table
Add a link
Reference in a new issue