A comprehensive TypeScript library providing type-safe authentication and authorization solutions for Web2 and Web3 applications with HSuite ecosystem.
Table of Contents
Quick Start
npm install @hsuite/auth-types
import { IAuth, Auth } from '@hsuite/auth-types';
// Use interfaces for type checking
const loginData: IAuth.ICredentials.IWeb2.IDto.ILogin = {
username: "john_doe",
email: "[email protected]",
password: "securePassword123"
};
// Use models for runtime logic
const loginDto = new Auth.Credentials.Web2.Dto.Login(loginData);
Key Features
Comprehensive TypeScript library for authentication and authorization type definitions
Complete set of TypeScript interfaces, models, and decorators for implementing secure, type-safe authentication across applications within the HSuite ecosystem.
class Authentication implements IAuth.IConfiguration.IAuthentication {
public enabled: boolean;
public commonOptions: IAuth.IConfiguration.IOptions;
public web2Options: IAuth.IConfiguration.IWeb2.IOptions;
public web3Options: IAuth.IConfiguration.IWeb3.IOptions;
}
Auth.Credentials.Web2.Dto.Login
class Login implements IAuth.ICredentials.IWeb2.IDto.ILogin {
public username: string;
public email: string;
public password: string;
}
Auth.Credentials.Web3.Entity
class Entity implements IAuth.ICredentials.IWeb3.IEntity {
public walletId: string;
public publicKey: string;
public balance: Array<IAuth.IConfiguration.IWeb3.ITokenGate.IEntity>;
}
Learn how to use authentication decorators for route protection and access control. Implement role-based permissions, public endpoints, and advanced authentication patterns.
Interface Reference Guide
Complete reference for all authentication interfaces and type definitions. Understand the authentication system architecture and type contracts.
Model Implementation Guide
How to use model classes for type-safe authentication data handling. Learn about concrete implementations and runtime logic patterns.
🎯 Examples
Role-Based Access Control
import { Controller, Get, Post, UseGuards } from '@nestjs/common';
import { Roles, Public, isTwoFactorAuth, bypassTokenGate } from '@hsuite/auth-types';
@Controller('api')
export class SecureController {
// Admin and moderator access
@Roles(['admin', 'moderator'])
@Get('admin-panel')
getAdminPanel() {
return { message: 'Welcome to admin panel' };
}
// Admin only access
@Roles(['admin'])
@Post('delete-user')
deleteUser() {
return { message: 'User deleted by admin' };
}
// Public endpoint (no auth required)
@Public()
@Get('public-info')
getPublicInfo() {
return { message: 'Public information' };
}
// Requires 2FA verification
@isTwoFactorAuth()
@Roles(['admin'])
@Post('critical-operation')
criticalOperation() {
return { message: 'Critical operation completed' };
}
// Bypasses token gate
@bypassTokenGate()
@Get('no-token-gate')
noTokenGate() {
return { message: 'Token gate bypassed' };
}
}