0.1.32 • Published 7 months ago

@ackplus/nest-auth v0.1.32

Weekly downloads
-
License
MIT
Repository
github
Last release
7 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

7 months ago

0.1.31

7 months ago

0.1.30

7 months ago

0.1.29

7 months ago

0.1.28

7 months ago

0.1.27

7 months ago

0.1.26

7 months ago

0.1.25

7 months ago

0.1.24

7 months ago

0.1.23

7 months ago

0.1.22

7 months ago

0.1.21

7 months ago

0.1.20

7 months ago

0.1.19

7 months ago

0.1.18

7 months ago

0.1.17

8 months ago

0.1.16

8 months ago

0.1.15

8 months ago

0.1.14

8 months ago

0.1.13

8 months ago

0.1.12

8 months ago

0.1.10

8 months ago

0.1.9

8 months ago

0.1.8

8 months ago

0.1.7

8 months ago

0.1.6

8 months ago

0.1.5

8 months ago

0.1.4

8 months ago

0.1.3

8 months ago

0.1.2

8 months ago

0.1.1

8 months ago

0.1.0

8 months ago

0.0.51

8 months ago

0.0.50

8 months ago

0.0.49

8 months ago

0.0.48

8 months ago

0.0.47

8 months ago

0.0.46

8 months ago

0.0.45

8 months ago

0.0.43

8 months ago

0.0.42

8 months ago

0.0.41

8 months ago

0.0.40

8 months ago

0.0.39

8 months ago

0.0.38

8 months ago

0.0.37

8 months ago

0.0.36

8 months ago

0.0.35

8 months ago

0.0.34

8 months ago

0.0.33

8 months ago

0.0.32

8 months ago

0.0.30

8 months ago

0.0.29

8 months ago

0.0.28

8 months ago

0.0.27

8 months ago

0.0.26

8 months ago

0.0.25

8 months ago

0.0.24

8 months ago

0.0.23

8 months ago