@sftech/nestjs-auth
v0.0.17
Published
This library provides authentication and authorization features for NestJS applications. It is part of a monorepo managed with [Nx](https://nx.dev).
Readme
This library provides authentication and authorization features for NestJS applications. It is part of a monorepo managed with Nx.
Table of Contents
Installation
Add the library to your project using npm:
npm install @sftech/ts-nestjs-authUsage
Import the module in your NestJS project:
import { NestjsAuthModule } from '@sftech/ts-nestjs-auth';Register the module in your AppModule:
import { Module } from '@nestjs/common';
import { NestjsAuthModule } from '@sftech/ts-nestjs-auth';
@Module({
imports: [NestjsAuthModule.register(config: IAuthenticationOptions)],
})
export class AppModule {}Add authentication options to your config:
{
"AUTH_PROVIDER": "OAUTH" | "local",
"AUTH_OAUTH_VALIDATION_URL": "url to authentication provider like keycloak to get userinfo"
}Features
- Authentication strategies (e.g., JWT, OAuth)
- Authorization guards and decorators for roles and public endpoints
- User and role models
- Extensible for custom authentication providers
Project Structure
The library is located in libs/nestjs-auth. Key files and folders:
src/— Source code of the librarysrc/lib/— Main modules, services, and guardsREADME.md— This documentationproject.json— Nx project configuration
Build
Build the library using Nx:
nx build nestjs-authThe output will be in the dist/libs/nestjs-auth directory.
Development
To develop or test the library:
- Make changes in
libs/nestjs-auth/src. - Run unit tests:
nx test nestjs-auth - Lint the code:
nx lint nestjs-auth
Troubleshooting
- If you encounter TypeScript build errors related to imports or project references, ensure you use the path aliases defined in the root
tsconfig.base.json. - Check that your
tsconfig.jsonfiles include the correctincludeandrootDirsettings. - For Nx workspace issues, verify the
project.jsonconfiguration.
Further Information
- See the Nx documentation for details on workspace management and build processes.
- For NestJS usage, refer to the NestJS documentation.
