8320a34035
Middleware runs before guards in NestJS — req.user was always undefined when TenantMiddleware executed, so req.tenantId was never set. Convert to TenantGuard (APP_GUARD, registered after JwtAuthGuard) so it runs after JWT validation and can read req.user.tenantId correctly. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
65 lines
2.2 KiB
TypeScript
65 lines
2.2 KiB
TypeScript
import { Module } from '@nestjs/common';
|
|
import { ConfigModule } from '@nestjs/config';
|
|
import { APP_GUARD, APP_INTERCEPTOR } from '@nestjs/core';
|
|
import { ScheduleModule } from '@nestjs/schedule';
|
|
import { AuthModule } from './auth/auth.module';
|
|
import { JwtAuthGuard } from './auth/guards/jwt-auth.guard';
|
|
import { RolesGuard } from './auth/guards/roles.guard';
|
|
import { ForcePasswordChangeInterceptor } from './auth/interceptors/force-password-change.interceptor';
|
|
import { HealthModule } from './health/health.module';
|
|
import { LdapModule } from './ldap/ldap.module';
|
|
import { MailModule } from './mail/mail.module';
|
|
import { CalendarModule } from './calendar/calendar.module';
|
|
import { DashboardModule } from './dashboard/dashboard.module';
|
|
import { DkvModule } from './dkv/dkv.module';
|
|
import { DomaincheckModule } from './domaincheck/domaincheck.module';
|
|
import { ModuleRegistryModule } from './module-registry/module-registry.module';
|
|
import { PrismaModule } from './prisma/prisma.module';
|
|
import { SettingsModule } from './settings/settings.module';
|
|
import { TenantGuard } from './tenant/tenant.guard';
|
|
import { TenantModule } from './tenant/tenant.module';
|
|
import { UserModule } from './user/user.module';
|
|
|
|
@Module({
|
|
imports: [
|
|
ConfigModule.forRoot({ isGlobal: true }),
|
|
ScheduleModule.forRoot(),
|
|
PrismaModule,
|
|
AuthModule,
|
|
UserModule,
|
|
TenantModule,
|
|
HealthModule,
|
|
MailModule,
|
|
LdapModule,
|
|
ModuleRegistryModule,
|
|
DomaincheckModule,
|
|
DashboardModule,
|
|
CalendarModule,
|
|
SettingsModule,
|
|
DkvModule,
|
|
],
|
|
providers: [
|
|
// Global JWT guard: all routes require auth unless @Public()
|
|
{
|
|
provide: APP_GUARD,
|
|
useClass: JwtAuthGuard,
|
|
},
|
|
// Runs after JwtAuthGuard — sets req.tenantId and req.tenantPrisma from req.user
|
|
{
|
|
provide: APP_GUARD,
|
|
useClass: TenantGuard,
|
|
},
|
|
// Global roles guard: checks @Roles() decorator
|
|
{
|
|
provide: APP_GUARD,
|
|
useClass: RolesGuard,
|
|
},
|
|
// Global interceptor: forces password change if mustChangePassword=true (D-06 / Pitfall 5)
|
|
{
|
|
provide: APP_INTERCEPTOR,
|
|
useClass: ForcePasswordChangeInterceptor,
|
|
},
|
|
],
|
|
})
|
|
export class AppModule {}
|