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 {}