From e2e031a0fc82041b19e046aa23527abed703b52e Mon Sep 17 00:00:00 2001 From: shancheas Date: Thu, 9 Feb 2023 17:24:55 +0700 Subject: [PATCH] feat: app module implement guard, interceptor, error handler --- src/app.module.ts | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 src/app.module.ts diff --git a/src/app.module.ts b/src/app.module.ts new file mode 100644 index 0000000..64b35f5 --- /dev/null +++ b/src/app.module.ts @@ -0,0 +1,39 @@ +import { Module, Scope } from '@nestjs/common'; +import { RefreshTokenInterceptor, SessionModule } from './core/sessions'; +import { AuthModule } from './auth/auth.module'; +import { JWTGuard } from './core/guards'; +import { APP_FILTER, APP_GUARD, APP_INTERCEPTOR } from '@nestjs/core'; +import { HttpExceptionFilter, TransformInterceptor } from './core/response'; + +@Module({ + imports: [SessionModule, AuthModule], + controllers: [], + providers: [ + /** + * By default all request from client will protect by JWT + * if there is some endpoint/function that does'nt require authentication + * please add `@Unprotected()` decorator to the function + */ + { + provide: APP_GUARD, + scope: Scope.REQUEST, + useClass: JWTGuard, + }, + { + provide: APP_INTERCEPTOR, + scope: Scope.REQUEST, + useClass: RefreshTokenInterceptor, + }, + { + provide: APP_INTERCEPTOR, + scope: Scope.REQUEST, + useClass: TransformInterceptor, + }, + { + provide: APP_FILTER, + scope: Scope.REQUEST, + useClass: HttpExceptionFilter, + }, + ], +}) +export class AppModule {}