Initial import of verae-middleware from zapier monorepo

This commit is contained in:
George Lambert 2026-09-11 13:50:53 -04:00
commit fb6db30e0e
66 changed files with 6590 additions and 0 deletions

View 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();
});