NestJS Adapter
Package: @nauth-toolkit/nestjs
Type: Framework Adapter
- npm
- Yarn
- pnpm
- Bun
npm install @nauth-toolkit/nestjs
yarn add @nauth-toolkit/nestjs
pnpm add @nauth-toolkit/nestjs
bun add @nauth-toolkit/nestjs
Exports
Module
| Export | Description |
|---|---|
AuthModule | Main module with forRoot() |
NAuthModuleConfig | Module configuration type |
Guards
| Export | Documentation |
|---|---|
AuthGuard | AuthGuard |
NAuthContextGuard | NAuthContextGuard |
CsrfGuard | CsrfGuard |
Decorators
| Export | Documentation |
|---|---|
@CurrentUser() | CurrentUser |
@Public() | Public |
IS_PUBLIC_KEY | Metadata key set by @Public() — use in custom guards |
@ClientInfo() | ClientInfo |
@TokenDelivery() | TokenDelivery |
TOKEN_DELIVERY_KEY | Metadata key set by @TokenDelivery() — use in custom interceptors |
RouteDelivery | Enum of delivery modes used with @TokenDelivery() |
@RequireRecaptcha() | RequireRecaptcha |
Hook Decorators
| Export | When It Fires |
|---|---|
@PreSignupHook() | Before a user account is created |
@PostSignupHook() | After a user account is created |
@UserProfileUpdatedHook() | After user profile attributes change |
@PasswordChangedHook() | After a password is changed |
@MFADeviceRemovedHook() | After an MFA device is removed |
@AdaptiveMFARiskDetectedHook() | When high-risk signin activity is detected |
@AccountStatusChangedHook() | After an account is enabled or disabled |
@EmailChangedHook() | After a user's email address is changed |
@AccountLockedHook() | After an account is locked |
@SessionsRevokedHook() | After user sessions are bulk revoked |
@MFAFirstEnabledHook() | After a user enables MFA for the first time |
HookDecoratorOptions | Options interface shared by all hook decorators |
Hooks Module
| Export | Description |
|---|---|
NAuthHooksModule | NAuthHooksModule — auto-registers lifecycle hook providers |
Interceptors
| Export | Documentation |
|---|---|
NAuthContextInterceptor | NAuthContextInterceptor |
CookieTokenInterceptor | CookieTokenInterceptor |
Filters
| Export | Documentation |
|---|---|
NAuthHttpExceptionFilter | NAuthHttpExceptionFilter |
Pipes
| Export | Documentation |
|---|---|
NAuthValidationPipe | NAuthValidationPipe |
Providers
| Export | Documentation |
|---|---|
NestJsLoggerAdapter | NestJsLoggerAdapter |
Services
| Export | Description |
|---|---|
CsrfService | CSRF token generation and validation service |
Storage Factories
| Export | Description |
|---|---|
createRedisStorageAdapter(url) | Redis session storage |
createDatabaseStorageAdapter() | Database session storage |
createRedisClusterAdapter(nodes) | Redis cluster storage |
Re-exports from Core
All exports from @nauth-toolkit/core:
- Services:
AuthService,MFAService,SocialAuthService, etc. - DTOs:
SignupDTO,LoginDTO,AuthResponseDTO, etc. - Interfaces:
NAuthConfig,IUser,ISession, etc. - Enums:
MFAMethod,AuthErrorCode, etc. - Exceptions:
NAuthException
AuthModule
forRoot()
AuthModule.forRoot(config: NAuthModuleConfig): DynamicModule
Example
import { Module } from '@nestjs/common';
import { TypeOrmModule } from '@nestjs/typeorm';
import { AuthModule } from '@nauth-toolkit/nestjs';
import { getNAuthEntities } from '@nauth-toolkit/database-typeorm-postgres';
@Module({
imports: [
TypeOrmModule.forRoot({
type: 'postgres',
entities: getNAuthEntities(),
}),
AuthModule.forRoot({
jwt: {
algorithm: 'HS256',
accessToken: { secret: 'secret', expiresIn: '15m' },
refreshToken: { secret: 'refresh', expiresIn: '7d' },
},
}),
],
})
export class AppModule {}