INSIGHT-MVP/packages/crm-service/src/auth/guards/tenant.guard.ts
Thomas Reitz ba4eec951a fix(crm): fix Lexware import 500 — tenantId validation in TenantGuard and service
- TenantGuard: remove PLATFORM_ADMIN bypass, require tenantId for all users
- lexware-contacts.service: add defensive tenantId check in importAsCompany
  and importAsContact with clear BadRequestException message

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-11 10:34:46 +01:00

25 lines
723 B
TypeScript

import {
Injectable,
CanActivate,
ExecutionContext,
ForbiddenException,
} from '@nestjs/common';
import { JwtPayload } from '../../common/decorators/current-user.decorator';
@Injectable()
export class TenantGuard implements CanActivate {
canActivate(context: ExecutionContext): boolean {
const request = context.switchToHttp().getRequest();
const user = request.user as JwtPayload;
// Alle User (auch PLATFORM_ADMIN) muessen eine tenantId haben
// um auf tenant-spezifische CRM-Ressourcen zuzugreifen.
if (!user?.tenantId) {
throw new ForbiddenException(
'Kein Mandant zugeordnet. Bitte mit einem mandanten-gebundenen Account anmelden.',
);
}
return true;
}
}