Install & Compatibility
Where this runs
No compatibility data collected yet for this library.
Code
Verified usage
Verified import paths — ran on the pinned version, not inferred.
AuthModule
✓ import { AuthModule } from 'clhq-auth-module'
✗ const AuthModule = require('clhq-auth-module')
ESM-only package; CommonJS require will fail.
JwtAuthGuard
✓ import { JwtAuthGuard } from 'clhq-auth-module'
✗ import { JWTGuard } from 'clhq-auth-module'
Guard name is case-sensitive and includes 'Auth'.
Roles
✓ import { Roles } from 'clhq-auth-module'
✗ import { Roles } from '@nestjs/passport'
Custom Roles decorator provided by this module, not from passport.
CurrentUser
✓ import { CurrentUser } from 'clhq-auth-module'
✗ import { Req } from '@nestjs/common'
Use this decorator to access the authenticated user in route handlers.
Shows how to import and configure AuthModule with a JWT secret in a NestJS application.
import { Module } from '@nestjs/common';
import { AuthModule } from 'clhq-auth-module';
import { AppController } from './app.controller';
@Module({
imports: [
AuthModule.forRoot({
jwtSecret: process.env.JWT_SECRET ?? '',
expiry: '1h',
}),
],
controllers: [AppController],
})
export class AppModule {}
Debug
Known issues
breakingThe module API is unstable in alpha versions; forRoot() options may change without notice.fixPin to a specific alpha version and monitor release notes.
affects: <1.0.0
deprecatedUsage of 'AuthModule.forRootAsync()' with factory provider is deprecated in favor of synchronous forRoot().fixPass configuration directly to forRoot().
affects: >=1.1.0-alpha.150
gotchaJwtAuthGuard must be applied to controllers or routes; it does not automatically protect all endpoints.fixAdd @UseGuards(JwtAuthGuard) to controller class or individual routes.
affects: >=1.0.0
breakingThe 'Roles' decorator previously accepted an array of strings; now requires an array of enums.fixDefine an enum for roles and pass an array of enum values.
affects: >=1.1.0-alpha.170
Errors
Common errors & fixes
Cannot find module 'clhq-auth-module' or its corresponding type declarations.
Missing npm install or TypeScript not configured to resolve the module.
fixRun 'npm install clhq-auth-module' and ensure 'moduleResolution' is 'node' or 'node16' in tsconfig.json.
Error: Forbidden resource
Request lacks valid JWT token or token is expired.
fixProvide a valid JWT token in the Authorization header: 'Bearer <token>'.
Nest can't resolve dependencies of the AuthModule (JwtAuthGuard, ...)
AuthModule.forRoot() not called or missing peer dependencies.
fixEnsure @nestjs/core and @nestjs/common are installed and AuthModule.forRoot() is added to the imports array.
Upgrade
Version history
1.1.0-alpha.189latest on npm
Audit
Dependencies
@nestjs/corerequiredPeer dependency for NestJS integration
@nestjs/commonrequiredPeer dependency for NestJS integration