@valentine-efagene/qshelter-common 2.0.24 → 2.0.25

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -9,6 +9,21 @@ declare global {
9
9
  interface Request {
10
10
  tenantContext?: TenantContext;
11
11
  tenantPrisma?: TenantPrismaClient | PrismaClient;
12
+ /**
13
+ * API Gateway context added by serverless-express
14
+ */
15
+ apiGateway?: {
16
+ event: {
17
+ requestContext: {
18
+ authorizer?: {
19
+ userId?: string;
20
+ email?: string;
21
+ roles?: string;
22
+ tenantId?: string;
23
+ };
24
+ };
25
+ };
26
+ };
12
27
  }
13
28
  }
14
29
  }
@@ -20,9 +20,12 @@ export function createTenantMiddleware(options) {
20
20
  const { prisma, createScopedClient = true } = options;
21
21
  return function tenantMiddleware(req, res, next) {
22
22
  try {
23
+ // 1. Try Lambda authorizer context first (production)
24
+ const authorizerContext = req.apiGateway?.event?.requestContext?.authorizer;
25
+ // 2. Fall back to headers (local dev or alternative setups)
23
26
  const headers = req.headers;
24
- const tenantId = headers['x-tenant-id'];
25
- const userId = headers['x-user-id'];
27
+ const tenantId = authorizerContext?.tenantId || headers['x-tenant-id'];
28
+ const userId = authorizerContext?.userId || headers['x-user-id'];
26
29
  if (!tenantId) {
27
30
  // For now, allow requests without tenant context for development
28
31
  // In production, you might want to reject these
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@valentine-efagene/qshelter-common",
3
- "version": "2.0.24",
3
+ "version": "2.0.25",
4
4
  "description": "Shared database schemas and utilities for QShelter services",
5
5
  "main": "dist/src/index.js",
6
6
  "types": "dist/src/index.d.ts",