Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/velascoandres/nestjs-auth-simple-boilerplate
A Nest.js boilerplate with authentication with jwt, verification emails, etc.
https://github.com/velascoandres/nestjs-auth-simple-boilerplate
auth-jwt nestjs nestjs-boilerplate
Last synced: about 2 months ago
JSON representation
A Nest.js boilerplate with authentication with jwt, verification emails, etc.
- Host: GitHub
- URL: https://github.com/velascoandres/nestjs-auth-simple-boilerplate
- Owner: velascoandres
- Created: 2022-10-16T02:26:57.000Z (about 2 years ago)
- Default Branch: main
- Last Pushed: 2024-02-15T17:34:40.000Z (11 months ago)
- Last Synced: 2024-04-13T19:27:57.942Z (9 months ago)
- Topics: auth-jwt, nestjs, nestjs-boilerplate
- Language: TypeScript
- Homepage:
- Size: 395 KB
- Stars: 2
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
Nestjs auth simple boilerplate
## Description
A Nest.js boilerplate with authentication with jwt, verification emails, etc.## ๐ Table of Contents
* [โญ๏ธ Highlights](#highlights)
* [๐ป Stack](#stack)
* [๐ Project Summary](#project-summary)
* [โ๏ธ Setting Up](#setting-up)
* [๐ Run Locally](#run-locally)
* [๐งช Run tests](#run-tests)
## โญ๏ธ Highlights
* JWT Authentication
* Refresh JWT token
* Send/Resend confirmation emails
* Change user password
* Change user email (email confirmation)## ๐ป Stack
- [nestjs/typeorm](https://github.com/nestjs/typeorm): Integration of TypeORM with NestJS for database management.
- [nestjs/swagger](https://github.com/nestjs/swagger): Generates OpenAPI (Swagger) documentation for the NestJS application.
- [nestjs/jwt](https://github.com/nestjs/jwt): JWT (JSON Web Token) authentication module for NestJS.
- [nestjs/passport](https://github.com/nestjs/passport): Authentication module for NestJS that supports various strategies.
- [nestjs/config](https://github.com/nestjs/config): Configuration module for NestJS applications.## ๐ Project Summary
- [**src/auth**](src/auth): Handles authentication-related functionalities such as decorators, guards, strategies, and validations.
- [**src/core**](src/core): Contains core project files and utilities.
- [**src/users**](src/users): Manages user-related functionalities including DTOs, entities, enums, and fixtures.
- [**src/test-utils**](src/test-utils): Provides utilities for testing purposes.
- [**templates**](templates): Holds template files for the project.
- [**views**](views): Manages view files for the project.## โ๏ธ Setting Up
Clone this repository. Set up your virtual environment (optional but recommended). Copy the contents of .env.example into a new file named .env and configure the required variables.
```text
APP_PORT=3000POSTGRES_URL="postgresql://bl_pg_user:bl_pg_password@localhost:4848/bl_pg_local_db"
POSTGRES_TEST_URL="postgresql://test_user:test_password@localhost:4949/bl_pg_test_db"JWT_ACCESS_SECRET="KEY_SECRET"
JWT_REFRESH_SECRET="KEY_SECRET"
JWT_EXPIRES="45min"
JWT_REFRESH_EXPIRES="1y"JWT_VERIFICATION_TOKEN_SECRET="123"
JWT_VERIFICATION_TOKEN_EXPIRATION_TIME="21600s"
EMAIL_CONFIRMATION_URL="http://localhost:3000/auth/email/confirm-email"JWT_FORGOT_PASSWORD_TOKEN_SECRET="123"
JWT_FORGOT_PASSWORD_TOKEN_EXPIRATION_TIME="21600s"
FORGOT_PASSWORD_URL="http://localhost:3000/auth/restore-password"MAIL_HOST=smtp.example.com
[email protected]
MAIL_PASSWORD=some-password
[email protected]
```#### APP_PORT
- Choose a port number for your application (e.g., 3000, 8080).#### POSTGRES_URL
- Replace `bl_pg_user` with the username for your PostgreSQL database.
- Replace `bl_pg_password` with the password for your PostgreSQL database.
- Replace `localhost:4848` with the host and port of your PostgreSQL database.
- Replace `bl_pg_local_db` with the name of your PostgreSQL database.> If you modify these values โโmake sure to change too at the docker-compose.yaml file
#### POSTGRES_TEST_URL
- Replace `test_user` with the username for your test PostgreSQL database.
- Replace `test_password` with the password for your test PostgreSQL database.
- Replace `localhost:4949` with the host and port of your test PostgreSQL database.
- Replace `bl_pg_test_db` with the name of your test PostgreSQL database.> If you modify these values โโmake sure to change too at the docker-compose.yaml file
#### JWT_ACCESS_SECRET
- Generate a secret key for signing JWT access tokens.#### JWT_REFRESH_SECRET
- Generate a secret key for signing JWT refresh tokens.#### JWT_EXPIRES
- Set the expiration time for JWT access tokens (e.g., 45min, 1h).#### JWT_REFRESH_EXPIRES
- Set the expiration time for JWT refresh tokens (e.g., 1d, 1y).#### JWT_VERIFICATION_TOKEN_SECRET
- Generate a secret key for signing JWT verification tokens.#### JWT_VERIFICATION_TOKEN_EXPIRATION_TIME
- Set the expiration time for JWT verification tokens (e.g., 21600s for 6 hours).#### EMAIL_CONFIRMATION_URL
- Set the URL where users will be redirected to confirm their email addresses.#### JWT_FORGOT_PASSWORD_TOKEN_SECRET
- Generate a secret key for signing JWT forgot password tokens.#### JWT_FORGOT_PASSWORD_TOKEN_EXPIRATION_TIME
- Set the expiration time for JWT forgot password tokens (e.g., 21600s for 6 hours).#### FORGOT_PASSWORD_URL
- Set the URL where users will be redirected to reset their passwords.#### MAIL_HOST
- Set the hostname of your email server (e.g., smtp.example.com).#### MAIL_USER
- Set the email address or username for authenticating with your email server.#### MAIL_PASSWORD
- Set the password for authenticating with your email server.#### MAIL_FROM
- Set the "From" email address that will be used for sending emails.## ๐ Run Locally
1. If you want to use the docker-compose file:
```sh
docker compose up -D
```
2.Install the dependencies with one of the package managers listed below:
```bash
pnpm install
```
3.Start the development mode:
```bash
pnpm start:dev
```## ๐งช Run tests
1. Run unit tests
```sh
pnpm test
```
2. Run coverage
```sh
pnpm test:cov
```