auth-be
This plugin provides authentication functionality for Rest & GraphQL APIs.
Tags
Backend
, Authentication
Features Overview
- User registration via email: Allows users to create new accounts using their email addresses.
- User login via email: Enables users to authenticate using their email and password.
- Forgot & password reset: Helps users with a password reset process via email.
- Renew access token: Enable users to renew access tokens.
Dependencies:
- NestJS: A framework for building efficient and scalable server-side applications.
- GraphQL: A query language for APIs that enables clients to request and retrieve specific data.
- Prisma: An open-source ORM for Node.js and TypeScript that simplifies database interactions.
- Postgres: Postgres is an open-source relational database management system that supports SQL (relational) and JSON (non-relational) querying.
Project Structure
auth-be/
|--src/
| |-- index.ts -> (plugin installation scripts)
|--template -> (nestjs project)
| |--src/
| | ├── app.module.ts
| | ├── auth
| | ├── authorization
| | ├── common
| | │ ├── dto
| | │ ├── enums
| | │ ├── filters
| | │ ├── interceptor
| | │ └── logger
| | ├── config
| | │ ├── env-config.module.ts
| | │ └── env.config.ts
| | ├── db
| | │ ├── @generated
| | │ │ └── index.ts
| | │ ├── auth
| | │ │ ├── auth-db.repository.ts
| | │ │ └── auth-db.service.ts
| | │ ├── db.module.ts
| | │ ├── db.service.ts
| | │ ├── dto
| | │ ├── helpers
| | │ └── prisma
| | └── main.ts
Installation
To install the auth-be
plugin, you can use the following command:
npx create-gs-project@latest add auth-be
Running the app
# Setup the Prisma client
$ npm run prisma:setup
# development
$ npm run start
# watch mode
$ npm run start:dev
# production mode
$ npm run start:prod
Post Installation steps
yarn install
ornpm install
- Create a
.env.development
file with all the variables present in the.env.example
file or runcp .env.example .env
. - Start the Docker containers:
docker-compose up -d
- Setup prisma models :
npm run prisma:setup
- Seed the database:
npm run prisma:seed
- Start the development server:
npm run start:dev
- Access GraphQL at:
http://localhost:3000/graphql
- Access Swagger at:
http://localhost:3000/api
Test
# unit tests
$ npm run test
# e2e tests
$ npm run test:e2e
# test coverage
$ npm run test:cov
Methods
authenticateUser
Validates user credentials (email and password) and returns an authentication response with tokens upon success.
registerUser
Registers a new user using the provided email and password.
renewAccessToken
Refreshes the access token for the current user.
initiatePasswordReset
Initiates the password reset process by sending a reset link to the user's email.
completePasswordReset
Resets the user's password to the provided new password.