feat: app module implement guard, interceptor, error handler

master
shancheas 2023-02-09 17:24:55 +07:00
parent b2a172c47a
commit e2e031a0fc
1 changed files with 39 additions and 0 deletions

39
src/app.module.ts Normal file
View File

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