A Nest.js boilerplate with authentication with jwt, verification emails, etc.
- JWT Authentication
- Refresh JWT token
- Send/Resend confirmation emails
- Change user password
- Change user email (email confirmation)
- nestjs/typeorm: Integration of TypeORM with NestJS for database management.
- nestjs/swagger: Generates OpenAPI (Swagger) documentation for the NestJS application.
- nestjs/jwt: JWT (JSON Web Token) authentication module for NestJS.
- nestjs/passport: Authentication module for NestJS that supports various strategies.
- nestjs/config: Configuration module for NestJS applications.
- src/auth: Handles authentication-related functionalities such as decorators, guards, strategies, and validations.
- src/core: Contains core project files and utilities.
- src/users: Manages user-related functionalities including DTOs, entities, enums, and fixtures.
- src/test-utils: Provides utilities for testing purposes.
- templates: Holds template files for the project.
- views: Manages view files for the project.
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.
APP_PORT=3000
POSTGRES_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
MAIL_USER=examples@mail.com
MAIL_PASSWORD=some-password
MAIL_FROM=noreply@example.com
- Choose a port number for your application (e.g., 3000, 8080).
- 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
- 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
- Generate a secret key for signing JWT access tokens.
- Generate a secret key for signing JWT refresh tokens.
- Set the expiration time for JWT access tokens (e.g., 45min, 1h).
- Set the expiration time for JWT refresh tokens (e.g., 1d, 1y).
- Generate a secret key for signing JWT verification tokens.
- Set the expiration time for JWT verification tokens (e.g., 21600s for 6 hours).
- Set the URL where users will be redirected to confirm their email addresses.
- Generate a secret key for signing JWT forgot password tokens.
- Set the expiration time for JWT forgot password tokens (e.g., 21600s for 6 hours).
- Set the URL where users will be redirected to reset their passwords.
- Set the hostname of your email server (e.g., smtp.example.com).
- Set the email address or username for authenticating with your email server.
- Set the password for authenticating with your email server.
- Set the "From" email address that will be used for sending emails.
- If you want to use the docker-compose file:
docker compose up -D
2.Install the dependencies with one of the package managers listed below:
pnpm install
3.Start the development mode:
pnpm start:dev
- Run unit tests
pnpm test
- Run coverage
pnpm test:cov