@quero-doar/core v0.1.2
Quero Doar Core
Welcome to the documentation of the core library of the Quero Doar. This library is responsible for providing central functionalities for the Quero Doar project, such as authentication management and server configuration. Here's everything you need to know to get started using this library.
Installation
To install this library, you can use the npm package manager. Simply type the following command in the terminal:
npm install @quero-doar/core
Features
Here's a list of features that this library provides:
Authentication
This library provides functionalities to manage user authentication. It supports authentication with JSON Web Tokens (JWT) and allows you to check if a user is authenticated and/or has permission to access a resource.
To use the authentication feature, simply import the AuthService service:
import { AuthService } from '@quero-doar/core';
@Injectable()
export class MyService {
constructor(private authService: AuthService) {}
async myMethod() {
// Check if user is authenticated
const user = await this.authService.authenticate(request);
// Check if user has permission to access a resource
await this.authService.authorize(user, 'read', 'resource');
// Generate a JWT token for a user
const token = await this.authService.generateToken(user);
}
}
Sever configuration
This library provides functionlities to configure the current server with some defaults. It creates server with Swagger, Validation Pipe, API Versioning, Helmet and Cors Enabled.
To use the server feature, simply import the startServer
function:
async function startApp() {
const app = await NestFactory.create(ControllerModule);
const port = process.env.PORT || '4000';
const title = 'Users API';
const description = 'This API deals with users from quero doar';
await startServer(app, port, title, description);
}
startApp();