GithubHelp home page GithubHelp logo

spidey-code / authentication-redis-nestjs Goto Github PK

View Code? Open in Web Editor NEW
5.0 1.0 0.0 117 KB

Project to demonstrate implmentation of redis in NestJs for OTP and authentication with using argon2 for hashing.

JavaScript 5.62% TypeScript 94.38%
argon2 authentication nestjs nestjs-backend redis redis-database redis-module nestjs-redis nestjs-authentication

authentication-redis-nestjs's Introduction

Auth-Redis-Nest

This Project demonstrate the Authenication module with Redis implmentation.
The purpose of this project is to implemented the redis with the NestJs
It is build with NestJs framework with MongoDB as Database and Redis database to store and verify OTP authenication.

Prerequisites

Tech should be installed before running the application

  1. NestJs
  2. Docker
  3. Redis
  4. MongoDB
  5. Postman (To execute the APIs)

Installing Guide

After cloning the project
Install Npm libraries using ย  npm i

Add .env file in the root folder with variables

DB_URL
#REDIS
REDIS_HOST
REDIS_PORT

To Run

Run redis in docker
Connect with Database
Run npm run start:dev to run the application
If everything is good you won't see red lines else you have stackoverflow to debug.

Brief Info about project

This is build with NestJs framework. I have created auth module which includes CRUD APIs with login and OTP verfication which is implmented using redis database. Later I have discussed more about redis.

Here, User can do the following actions:

  1. Create User
  2. Login User
  3. Get all Users
  4. Get User by Id
  5. Update User
  6. Delete User
  7. Request Otp for User
  8. Verfiy Otp for User

I have use argon2 library for hashing. Redis for OTP verfication as it gives more feature above normal database.
It stores at key value pair so you don't have to manage the occurence of redundany. It has Time to live (TTL) which can be used to expire otp in certain specified time.

POSTMAN file for the APIs

Copy and paste below code in a file with .json extension and import it in the postman

{
	"info": {
		"_postman_id": "68a8f2e8-24a7-4533-9337-1df99e9f17ad",
		"name": "RedisOtp",
		"schema": "https://schema.getpostman.com/json/collection/v2.1.0/collection.json",
		"_exporter_id": "24806169"
	},
	"item": [
		{
			"name": "Get users",
			"request": {
				"method": "GET",
				"header": [],
				"url": {
					"raw": "{{base_url}}/users",
					"host": [
						"{{base_url}}"
					],
					"path": [
						"users"
					]
				}
			},
			"response": []
		},
		{
			"name": "Create user",
			"request": {
				"method": "GET",
				"header": []
			},
			"response": []
		},
		{
			"name": "Login user",
			"request": {
				"method": "GET",
				"header": []
			},
			"response": []
		},
		{
			"name": "Get user by id",
			"request": {
				"method": "GET",
				"header": []
			},
			"response": []
		},
		{
			"name": "UpdateUser",
			"request": {
				"method": "PATCH",
				"header": [],
				"body": {
					"mode": "raw",
					"raw": "{\r\n    \"userName\":\"newUser\"\r\n}",
					"options": {
						"raw": {
							"language": "json"
						}
					}
				},
				"url": {
					"raw": "{{base_url}}/users/update?userId=63f6014e256f9ecc6586f296",
					"host": [
						"{{base_url}}"
					],
					"path": [
						"users",
						"update"
					],
					"query": [
						{
							"key": "userId",
							"value": "63f6014e256f9ecc6586f296"
						}
					]
				}
			},
			"response": []
		},
		{
			"name": "Delete User",
			"request": {
				"method": "GET",
				"header": []
			},
			"response": []
		},
		{
			"name": "Generate OTP",
			"request": {
				"method": "GET",
				"header": []
			},
			"response": []
		},
		{
			"name": "Verify OTP",
			"request": {
				"method": "GET",
				"header": []
			},
			"response": []
		}
	]
}

Things can be improve

  1. I have added dtos for some APIs you can added them
  2. Tokens were not scope of my agenda but you can added them for session
  3. Caching can be added for quick response like for getAll users

Please add suggestion if you thing something is not right. Help us to improve

Keep coding

authentication-redis-nestjs's People

Contributors

spidey-code avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

authentication-redis-nestjs's Issues

Add tokenization

In this demo project, I haven't added any tokenization for sessions. Though it has login and related APIs. Please add if you want to contribute. If you are a newbie, it would be a great exercise for you.

Add Caching using redis

I have added redis for OTP verification purpose. Though it would be great to added caching as it is widley used for this purpose.
Please add comment if you need any help

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.