@ackplus/nest-auth v0.1.32
Nest Auth
A comprehensive authentication module for NestJS applications.
Table of Contents
- Installation
- Quick Start
- Configuration
- Database Setup
- Testing
- Authentication Providers
- API Documentation
- Contributing
- License
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
Variable | Description | Default |
---|---|---|
DATABASE_URL | Database connection URL | :memory: |
NODE_ENV | Application environment | development |
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
- Create a new database:
CREATE DATABASE your_database;
- Run migrations:
yarn typeorm migration:run -d src/typeorm.config.ts
SQLite
No setup required. The database will be created automatically.
Testing
Local Development
- For PostgreSQL:
DATABASE_URL=postgresql://user:password@localhost:5432/testdb yarn test
- 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
Endpoint | Method | Description |
---|---|---|
/auth/login | POST | Login with credentials |
/auth/register | POST | Register new user |
/auth/refresh | POST | Refresh access token |
/auth/logout | POST | Logout user |
Request/Response Examples
Login Request
{
"providerId": "email",
"credentials": {
"email": "user@example.com",
"password": "password123"
}
}
Login Response
{
"accessToken": "eyJhbGciOiJIUzI1NiIs...",
"refreshToken": "eyJhbGciOiJIUzI1NiIs...",
"isRequiresMfa": false
}
Contributing
- Fork the repository
- Create your feature branch (
git checkout -b feature/amazing-feature
) - Commit your changes (
git commit -m 'Add some amazing feature'
) - Push to the branch (
git push origin feature/amazing-feature
) - Open a Pull Request
Development Setup
- Clone the repository
- Install dependencies:
yarn install
- Set up the database:
# For PostgreSQL
DATABASE_URL=postgresql://user:password@localhost:5432/testdb
# For SQLite
DATABASE_URL=:memory:
- 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.
4 months ago
4 months ago
4 months ago
4 months ago
4 months ago
4 months ago
4 months ago
4 months ago
4 months ago
4 months ago
4 months ago
4 months ago
4 months ago
4 months ago
4 months ago
5 months ago
5 months ago
5 months ago
5 months ago
5 months ago
5 months ago
5 months ago
5 months ago
5 months ago
5 months ago
5 months ago
5 months ago
5 months ago
5 months ago
5 months ago
5 months ago
5 months ago
5 months ago
5 months ago
5 months ago
5 months ago
5 months ago
5 months ago
5 months ago
5 months ago
5 months ago
5 months ago
5 months ago
5 months ago
5 months ago
5 months ago
5 months ago
5 months ago
5 months ago
5 months ago
5 months ago
5 months ago
5 months ago
5 months ago
5 months ago
5 months ago
5 months ago
5 months ago
5 months ago