Skip to content

AuthModule

@noctcore/auth-nestjs: a NestJS module for @noctcore/auth.

  • AuthModule.forRoot / forRootAsync provide the createAuth result under AUTH, register SessionGuard globally (closed by default, @Public() to open a route) and run CsrfMiddleware before every route.
  • @CurrentUser(), @CurrentSession() and @AuthMeta() read what the guard resolved; @RequireRole() and @RequireFreshAuth() narrow a route.
  • SessionCookies writes a new or ended session with its CSRF token.
  • configureTrustProxy and trustedHopsFromEnv read TRUST_PROXY and refuse to start in production without it.
  • describeRoutes lists every route with its access rule, for a test.

Express is the supported platform, for HTTP controllers. GraphQL, WebSocket and microservice handlers are refused unless @Public().

  • NestModule
  • OnModuleInit
  • BeforeApplicationShutdown

new AuthModule(discovery, reflector, options): AuthModule

DiscoveryService

Reflector

ResolvedOptions

AuthModule

beforeApplicationShutdown(): Promise<void>

Refuses to boot on a route whose decorators contradict each other, such as @Public() on a controller and @RequireRole() on one of its handlers, instead of leaving it to the guard to pick one at request time.

Promise<void>

BeforeApplicationShutdown.beforeApplicationShutdown


configure(consumer): void

MiddlewareConsumer

void

NestModule.configure


static forRoot<U>(options): DynamicModule

U extends AuthUser

AuthModuleOptions<U>

DynamicModule


static forRootAsync<U>(options): DynamicModule

U extends AuthUser

AuthModuleAsyncOptions<U>

DynamicModule


onModuleInit(): void

void

OnModuleInit.onModuleInit