/express-authorization-with-sessions

Authorization in express with session - a out role-based authorization project in Node

Primary LanguageJavaScript

Express authorization in Node - role-based authorization

This repository contains sample code on how implement a role-based authorization in Node with use Redis with session-based authentication in Node and Express.js.

Please help this repo with a ⭐️ if you find it useful! 😁

This repository is part of the Sessions in express.js tutorial series on YouTube provided by jangoebel.com.

Express sessions with redis

For updates, please reach out to @_jgoebel on Twitter.

Role-based authorization

This repository illustrates how to implement an authorization system in Express.js that blocks a user who does not have sufficient rights to perform a particular operation.

We use sessions as a means to log users in and that's why this project also requires you to run Redis locally.

Running this project

1. Installing Redis

Make sure that you have Redis running locally* on your machine on its _default* port 6379.

This project assumes that your Redis instance does not require a password (which is the default).

If your local Redis requires a password, please update the db/redis.js file to include the password field:

const redisClient = redis.createClient({
    port: 6379,
    host: 'localhost',
    password: 'your-password'
});

If you are on macOS, the easiest way to start up a Redis instance is by using Homebrew

brew install redis
brew services start redis

To stop Redis, you can run

brew services  stop redis

2. Install dependencies

Run:

npm install

to install the project's dependencies.

3. Start server

Execute the dev script to start up your server.

npm run dev