From 1dc1bc4aa3adf82a743b94bc2daeac96e8d48d79 Mon Sep 17 00:00:00 2001 From: sdraris Date: Wed, 27 Aug 2025 14:48:18 +0200 Subject: [PATCH] authguard and roleguard applied --- src/main.ts | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/main.ts b/src/main.ts index b407fa0..ed371b1 100644 --- a/src/main.ts +++ b/src/main.ts @@ -1,8 +1,11 @@ -import { NestFactory } from '@nestjs/core'; +import { NestFactory, Reflector } from '@nestjs/core'; import { AppModule } from './app.module'; import { ConfigService } from '@nestjs/config'; import { SwaggerModule } from '@nestjs/swagger/dist/swagger-module'; import { DocumentBuilder } from '@nestjs/swagger'; +import { AuthGuard } from './common/guards/auth.guard'; +import { JwtService } from '@nestjs/jwt'; +import { RolesGuard } from './common/guards/roles.guard'; async function bootstrap() { const app = await NestFactory.create(AppModule); @@ -20,6 +23,12 @@ async function bootstrap() { const document = SwaggerModule.createDocument(app, config); SwaggerModule.setup('api/docs', app, document); + const reflector = app.get(Reflector); + app.useGlobalGuards( + new AuthGuard(app.get(JwtService)), + new RolesGuard(reflector) + ); + await app.listen(port); console.log(`✅ P'titsPas API is running on: ${await app.getUrl()}`); }