@algorixa/auth_utils
v1.0.4
Published
Authentication utilities for users with roles
Readme
Auth Module
A lightweight authentication module for NestJS/Express-based applications.
This package provides decorators, middlewares, and utilities to handle
authorization and user validation via JWT tokens and MongoDB.
Features
Decorators (
AuthClass,AuthGuard) for NestJS to protect routes/classes based on roles.Middleware (
authMiddleware) for Express to guard routes based on roles.Utilities (
AuthUtils) to parse and validate JWT tokens, retrieve users from tokens, etc.Initialization (
InitializeModule) to configure the module with the environment needed for MongoDB connection and JWT secret before using any utilities.Note: If no required roles were added to decorators or middlewares when called, they will only check if the user is authenticated.
Installation
npm install @algorixa/auth_utilsInitialization
Before calling any of this module’s decorators or utilities, you must first initialize the module by calling the InitializeModule function. This function configures the database nnection and sets the JWT secret.
import { InitializeModule } from '@algorixa/auth_utils';
(async () => {
await InitializeModule({
JWT_SECRET: 'your_jwt_secret_here',
USERS_DB_URI: 'your_mongo_db_url_here',
});
// Now you can safely use the module’s decorators and utilities
})();