HbarSuite Docs
  • Welcome to HbarSuite
  • HbarSuite Developer Documentation
    • HbarSuite Smart Engine Applications
      • @hsuite/cross-chain-exchange
      • @hsuite/dao
      • @hsuite/exchange
      • @hsuite/launchpad
      • @hsuite/multisig
      • @hsuite/nft-exchange
    • HSuite Libraries
      • @hsuite/api-key
      • @hsuite/auth-types
      • @hsuite/auth
      • @hsuite/client-types
      • @hsuite/client
      • @hsuite/dkg-types
      • @hsuite/hashgraph-types
      • @hsuite/health
      • @hsuite/helpers
      • @hsuite/ipfs
      • @hsuite/smart-config
      • @hsuite/smart-network-types
      • @hsuite/smart-transaction-types
      • @hsuite/smartnode-sdk
      • @hsuite/snapshots
      • @hsuite/subscriptions-types
      • @hsuite/subscriptions
      • @hsuite/throttler-types
      • @hsuite/throttler
      • @hsuite/users-types
      • @hsuite/users
      • @hsuite/validators-types
  • General Documentation
    • Tokenomics
      • Tokenomics v1
      • Tokenomics V2
    • Smart Apps and Interaction
      • Subscription-Based Model
      • Token-Gate Model
    • The Smart Node Network
      • security-layer
        • Security Layer Integration
        • Setting Up Secure Clusters
        • Generating and Sharing Keys Collaboratively
        • Protecting Secrets with Shamir's Method
        • Managing Cluster Membership
        • Handling Node Expulsion and Replacement
        • Automating Responses to Network Changes & Key Rotation
        • Ensuring Continuous Operation and Recovery
      • Understanding Validators in Our System
        • Type of Validators Explained
    • What is a Smart Node?
  • Restful APIs Documentation
Powered by GitBook
On this page
  • Features
  • Installation
  • Usage
  • Module Setup
  • Basic Usage Examples
  • API Reference
  • UsersService
  • User Entity
  • Architecture
  • Database
  • Security
  • Dependencies
  • License
  1. HbarSuite Developer Documentation
  2. HSuite Libraries

@hsuite/users

A comprehensive user management library for HbarSuite applications that provides robust user authentication, profile management, and security features.

Features

  • User Management

    • User registration and account creation

    • Profile lookup and search functionality

    • Account deletion and management

    • Email verification system

  • Authentication & Security

    • Secure password management with hashing

    • Two-factor authentication (2FA) support

    • Email verification workflows

    • Password update and recovery processes

  • Data Management

    • MongoDB integration with Mongoose

    • Type-safe data models

    • Automatic timestamps

    • Collection management

Installation

npm install @hsuite/users

Usage

Module Setup

Import the UsersModule in your application:

import { Module } from '@nestjs/common';
import { UsersModule } from '@hsuite/users';

@Module({
  imports: [UsersModule]
})
export class AppModule {}

Basic Usage Examples

  1. User Creation

constructor(private usersService: UsersService) {}

async createUser() {
  const user = await this.usersService.create({
    email: '[email protected]',
    password: 'securepass123',
    username: 'johndoe'
  });
}
  1. Finding Users

// Find by ID
const user = await this.usersService.findById('507f1f77bcf86cd799439011');

// Find by credentials
const user = await this.usersService.find({
  email: '[email protected]',
  password: 'userpass123'
});
  1. Security Management

// Update password
await this.usersService.updatePassword(
  '[email protected]',
  'newSecurePass123'
);

// Configure 2FA
await this.usersService.updateTwoFactorAuth('userId', {
  enabled: true,
  secret: 'TOTP_SECRET_KEY',
  verified: false
});

API Reference

UsersService

Core service providing user management functionality:

  • create(user: User): Promise<UserDocument>

  • findById(userId: string): Promise<UserDocument>

  • find(credentials: IAuth.ICredentials.IWeb2.IDto.ILogin): Promise<UserDocument>

  • updateTwoFactorAuth(userId: string, twoFactorAuth: IAuth.ITwoFactor.IAuth): Promise<UserDocument>

  • updatePassword(userEmail: string, newPassword: string): Promise<UserDocument>

  • emailConfirmation(userId: string): Promise<UserDocument>

  • delete(user: IAuth.ICredentials.IWeb2.IDto.ISignup): Promise<UserDocument>

User Entity

The User entity extends UserNamespace.Safe and includes:

  • Required fields:

    • password: Hashed password string

    • Additional fields inherited from UserNamespace.Safe

  • Features:

    • Mongoose schema integration

    • Automatic timestamps

    • Pre-save validation

    • Collection management

Architecture

The library is structured into several key components:

  • UsersModule: Main module that orchestrates all user-related functionality

  • UsersService: Core business logic implementation

  • UserModelModule: Database operations and schema management

  • User Entity: Data model and validation rules

Database

The library uses MongoDB through Mongoose with the following configuration:

  • Collection name: auth_users

  • Schema features:

    • Pre-save validation

    • Automatic timestamps

    • Secure password hashing

    • Type-safe fields

Security

Built-in security features include:

  • Secure password hashing using bcrypt

  • Two-factor authentication support

  • Email verification system

  • Timing attack protection

  • One-way password hashing

Dependencies

  • @nestjs/common

  • @nestjs/mongoose

  • mongoose

  • @hsuite/auth-types

  • @hsuite/users-types

  • @hsuite/nestjs-swagger

License

[License information not found in source code]

Built with ❤️ by the HbarSuite Team Copyright © 2024 HbarSuite. All rights reserved.

Previous@hsuite/users-typesNext@hsuite/validators-types

Last updated 3 months ago