🚀 Initialize Musadaq SaaS: Full Backend + AI + React Dashboard + Docker Setup
This commit is contained in:
32
backend/src/common/middleware/tenant.middleware.ts
Normal file
32
backend/src/common/middleware/tenant.middleware.ts
Normal file
@@ -0,0 +1,32 @@
|
||||
/**
|
||||
* ════════════════════════════════════════════════════════════
|
||||
* مُصادَق (Musadaq) — Tenant Middleware
|
||||
* ════════════════════════════════════════════════════════════
|
||||
* يستخرج tenantId من JWT ويضعه في request.
|
||||
* يستخدم في تصفية البيانات (Query filtering).
|
||||
* ════════════════════════════════════════════════════════════
|
||||
*/
|
||||
|
||||
import {
|
||||
Injectable,
|
||||
NestMiddleware,
|
||||
UnauthorizedException,
|
||||
} from '@nestjs/common';
|
||||
import { Request, Response, NextFunction } from 'express';
|
||||
|
||||
@Injectable()
|
||||
export class TenantMiddleware implements NestMiddleware {
|
||||
use(req: Request, res: Response, next: NextFunction) {
|
||||
const { user } = req as any;
|
||||
|
||||
if (!user || !user.tenantId) {
|
||||
// Phase 1: Not always required (registration, login)
|
||||
return next();
|
||||
}
|
||||
|
||||
// Set tenant context for the request
|
||||
(req as any).tenantId = user.tenantId;
|
||||
|
||||
next();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user