π@hsuite/auth - Authentication & User Management Module
π Comprehensive NestJS authentication module providing unified Web2 & Web3 authentication, user management, and API key authentication
A robust, enterprise-grade authentication module that seamlessly integrates traditional username/password authentication with cutting-edge Web3 wallet-based authentication, complete user management, and API key authentication system, designed specifically for the HSuite ecosystem.
Table of Contents
Quick Start
Installation
npm install @hsuite/authBasic Setup
Protect Your Routes
Architecture
Core Components
π‘οΈ Guards
JwtAuthGuard- JWT-based route protectionRedisAuthGuard- Redis session authenticationConfirmedAuthGuard- Email confirmation requirementApiKeyAuthGuard- API key authentication guard
π Strategies
JwtStrategy- Passport JWT strategy implementationRedisStrategy- Redis-based session strategyWeb3Strategy- Blockchain wallet authenticationApiKeyStrategy- Header-based API key validation
π§ Services
AuthService- Core authentication logicUsersService- User management operationsApiKeyService- API key validationAuthController- REST API endpoints
π₯ User Management
UsersModule- Complete user management moduleUsersService- User CRUD operations and business logicUserModelService- Database operations with MongooseUser Entity- Mongoose schema and TypeScript types
π API Key Authentication
ApiKeyModule- API key authentication moduleApiKeyService- API key validation and managementApiKeyAuthGuard- Route protection with API keysApiKeyStrategy- Passport strategy for API keys
Module Structure
API Reference
AuthModule
Static Methods
forRootAsync(options: AuthModuleAsyncOptions): DynamicModule
Configures the authentication module with async dependency injection.
AuthService
Core Methods
validateUser(username: string, password: string): Promise<any>
Validates user credentials for Web2 authentication
login(user: any): Promise<{ access_token: string }>
Generates JWT token for authenticated user
register(userData: CreateUserDto): Promise<User>
Registers new user with email confirmation
Guards Reference
JwtAuthGuard
RedisAuthGuard
ConfirmedAuthGuard
Guides
Web2 Authentication Guide
Learn how to implement traditional username/password authentication with email confirmation and 2FA. Configure user registration, login flows, password reset, and session management.
Web3 Authentication Guide
Implement blockchain wallet-based authentication with signature verification and token gating. Set up wallet connection, signature validation, and decentralized identity management.
Session Management Guide
Configure Redis-based session management for distributed applications. Implement session storage, expiration policies, and cross-service session sharing.
Guards & Strategies Guide
Deep dive into authentication guards and Passport strategies. Create custom guards, implement authorization logic, and manage authentication flows.
Examples
Complete Module Configuration
Multi-Guard Protection
Integration
Required Dependencies
Environment Variables
TypeScript Configuration
π Note: This module requires proper configuration of external services (Redis, PostgreSQL, SMTP, Twilio) for full functionality. See individual guides for detailed setup instructions.
Built with β€οΈ by the HSuite Team Copyright Β© 2025 HSuite. All rights reserved.
Last updated