Skip to content

temirlannz/nestjs-session-auth

Repository files navigation

Nest Logo

A progressive Node.js framework for building efficient and scalable server-side applications.

NPM Version Package License NPM Downloads CircleCI Coverage Discord Backers on Open Collective Sponsors on Open Collective Donate us Support us Follow us on Twitter

Description

Session-Based Authentication in NestJS with Redis, with passwordless OTP, enables secure and scalable user sessions by storing session data in Redis and authenticating users via one-time passwords (OTP) instead of traditional passwords.

Project setup

Create .env.development in your root directory

APP_PORT=8001

ALLOWED_ORIGIN=http://localhost:3001

COOKIE_SECRET=secret
SESSION_SECRET=secret
SESSION_NAME=session_auth
SESSION_DOMAIN=localhost
SESSION_MAX_AGE=86400000
SESSION_HTTP_ONLY=false
SESSION_SECURE=false
SESSION_FOLDER=sessions_dev:
SESSION_SAME_SITE=lax

POSTGRES_USER=postgres
POSTGRES_PASSWORD=postgres123
POSTGRES_HOST=postgres
POSTGRES_PORT=5432
POSTGRES_DB=db_backend
POSTGRES_URI=postgresql://${POSTGRES_USER}:${POSTGRES_PASSWORD}@${POSTGRES_HOST}:${POSTGRES_PORT}/${POSTGRES_DB}

REDIS_PASSWORD=redis123
REDIS_HOST=redis
REDIS_PORT=6379
REDIS_URI=redis://default:redis123@redis:6379
$ yarn install
$ docker compose --env-file .env.development build
$ docker compose --env-file .env.development up --watch

Compile and run the project

# development
$ yarn run start

# watch mode
$ yarn run start:dev

# production mode
$ yarn run start:prod

Run tests

# unit tests
$ yarn run test

# e2e tests
$ yarn run test:e2e

# test coverage
$ yarn run test:cov

Resources

Check out a few resources that may come in handy when working with NestJS:

  • Visit the NestJS Documentation to learn more about the framework.
  • For questions and support, please visit our Discord channel.
  • To dive deeper and get more hands-on experience, check out our official video courses.
  • Visualize your application graph and interact with the NestJS application in real-time using NestJS Devtools.
  • Need help with your project (part-time to full-time)? Check out our official enterprise support.
  • To stay in the loop and get updates, follow us on X and LinkedIn.
  • Looking for a job, or have a job to offer? Check out our official Jobs board.

Support

Nest is an MIT-licensed open source project. It can grow thanks to the sponsors and support by the amazing backers. If you'd like to join them, please read more here.

Stay in touch

License

Nest is MIT licensed.

About

Session-Based Authentication in NestJS with Redis, with passwordless OTP, enables secure and scalable user sessions by storing session data in Redis and authenticating users via one-time passwords (OTP) instead of traditional passwords.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors