0.1.32 • Published 11 months ago

@ackplus/nest-auth v0.1.32

Weekly downloads
-
License
MIT
Repository
github
Last release
11 months ago

Nest Auth

A comprehensive authentication module for NestJS applications.

Table of Contents

Installation

yarn add @ackplus/nest-auth

Quick Start

import { NestAuthModule } from '@ackplus/nest-auth';

@Module({
  imports: [
    NestAuthModule.forRoot({
      jwt: {
        secret: 'your-secret-key',
      },
      emailAuth: {
        enabled: true,
      },
      // ... other options
    }),
  ],
})
export class AppModule {}

Configuration

Database Configuration

The module supports both PostgreSQL and SQLite databases. Configure your database connection using the DATABASE_URL environment variable:

# For PostgreSQL
DATABASE_URL=postgresql://user:password@localhost:5432/dbname

# For SQLite
DATABASE_URL=:memory:  # For in-memory database
DATABASE_URL=./database.sqlite  # For file-based database

Environment Variables

VariableDescriptionDefault
DATABASE_URLDatabase connection URL:memory:
NODE_ENVApplication environmentdevelopment

Module Options

interface AuthModuleOptions {
  jwt: {
    secret: string;
    expiresIn?: string;
  };
  emailAuth?: {
    enabled: boolean;
    // ... other email auth options
  };
  phoneAuth?: {
    enabled: boolean;
    // ... other phone auth options
  };
  // ... other options
}

Database Setup

PostgreSQL

  1. Create a new database:
CREATE DATABASE your_database;
  1. Run migrations:
yarn typeorm migration:run -d src/typeorm.config.ts

SQLite

No setup required. The database will be created automatically.

Testing

Local Development

  1. For PostgreSQL:
DATABASE_URL=postgresql://user:password@localhost:5432/testdb yarn test
  1. For SQLite:
DATABASE_URL=:memory: yarn test

CI/CD (GitHub Actions)

The tests run automatically in GitHub Actions using SQLite for faster execution. No additional setup required.

Authentication Providers

Email Authentication

@Post('login')
async login(@Body() loginDto: LoginRequestDto) {
  return this.authService.login({
    providerId: 'email',
    credentials: {
      email: loginDto.email,
      password: loginDto.password,
    },
  });
}

Phone Authentication

@Post('login')
async login(@Body() loginDto: LoginRequestDto) {
  return this.authService.login({
    providerId: 'phone',
    credentials: {
      phone: loginDto.phone,
      password: loginDto.password,
    },
  });
}

API Documentation

Authentication Endpoints

EndpointMethodDescription
/auth/loginPOSTLogin with credentials
/auth/registerPOSTRegister new user
/auth/refreshPOSTRefresh access token
/auth/logoutPOSTLogout user

Request/Response Examples

Login Request

{
  "providerId": "email",
  "credentials": {
    "email": "user@example.com",
    "password": "password123"
  }
}

Login Response

{
  "accessToken": "eyJhbGciOiJIUzI1NiIs...",
  "refreshToken": "eyJhbGciOiJIUzI1NiIs...",
  "isRequiresMfa": false
}

Contributing

  1. Fork the repository
  2. Create your feature branch (git checkout -b feature/amazing-feature)
  3. Commit your changes (git commit -m 'Add some amazing feature')
  4. Push to the branch (git push origin feature/amazing-feature)
  5. Open a Pull Request

Development Setup

  1. Clone the repository
  2. Install dependencies:
yarn install
  1. Set up the database:
# For PostgreSQL
DATABASE_URL=postgresql://user:password@localhost:5432/testdb

# For SQLite
DATABASE_URL=:memory:
  1. Run tests:
yarn test

Testing Guidelines

  • Write tests for all new features
  • Ensure tests pass in both PostgreSQL and SQLite
  • Follow the existing test patterns
  • Use appropriate test fixtures

License

This project is licensed under the MIT License - see the LICENSE file for details.

0.1.32

11 months ago

0.1.31

11 months ago

0.1.30

11 months ago

0.1.29

11 months ago

0.1.28

11 months ago

0.1.27

11 months ago

0.1.26

11 months ago

0.1.25

11 months ago

0.1.24

11 months ago

0.1.23

11 months ago

0.1.22

11 months ago

0.1.21

11 months ago

0.1.20

11 months ago

0.1.19

11 months ago

0.1.18

11 months ago

0.1.17

11 months ago

0.1.16

11 months ago

0.1.15

11 months ago

0.1.14

11 months ago

0.1.13

11 months ago

0.1.12

11 months ago

0.1.10

11 months ago

0.1.9

11 months ago

0.1.8

11 months ago

0.1.7

11 months ago

0.1.6

11 months ago

0.1.5

11 months ago

0.1.4

11 months ago

0.1.3

11 months ago

0.1.2

11 months ago

0.1.1

11 months ago

0.1.0

11 months ago

0.0.51

12 months ago

0.0.50

12 months ago

0.0.49

12 months ago

0.0.48

12 months ago

0.0.47

12 months ago

0.0.46

12 months ago

0.0.45

12 months ago

0.0.43

12 months ago

0.0.42

12 months ago

0.0.41

12 months ago

0.0.40

12 months ago

0.0.39

12 months ago

0.0.38

12 months ago

0.0.37

12 months ago

0.0.36

12 months ago

0.0.35

12 months ago

0.0.34

12 months ago

0.0.33

12 months ago

0.0.32

12 months ago

0.0.30

12 months ago

0.0.29

12 months ago

0.0.28

12 months ago

0.0.27

12 months ago

0.0.26

12 months ago

0.0.25

12 months ago

0.0.24

12 months ago

0.0.23

12 months ago