0.0.122 • Published 6 years ago

2max-express-authenticate v0.0.122

Weekly downloads
34
License
ISC
Repository
gitlab
Last release
6 years ago

Express authenticate

Simply authentication for express based on Sequelize.

Install

npm i 2max-express-authenticate --save

Configuration

const express = require('express');
const app = express();
const auth = require('2max-express-authenticate');

async function main(app) {
  // Declare auth + configure for persistence
  const util = await auth(app, {
    'persistence': {
      'host': process.env.MYSQL_HOST,
      'user': process.env.MYSQL_USER,
      'password': process.env.MYSQL_PASSWORD,
      'database': process.env.MYSQL_DATABASE,
      'dialect': 'mysql'
    }
  });

  // Secure yours routes with auth
  util.secure([
    '/admin',
    '/dashboard',
    ...
  ]);

  // Override connection method for send custom results
  util.override({
    'login': (req, res) => {
      res.send('Congrats');
     },
     'logout': (req, res) => {
       res.send('OUT');
     },
     'signup': (req, res) => {
       res.send('Good job mother fucker men');
     }
  });
}

app.listen(80);

Route

MethodendpointBody
POST/signup{username, password}
POST/login{username, password}
GET/logoutN/A

Features

  • Crypt password with bcrypt
  • Login, logout and signup (cookies + session)
  • Persist data (according to sequelize compatibility)
  • Give array with route to check session for each route
  • Enable middlewares for set response from /login, /logout and /signup

Todo

  • Add roles checking (bitmask)
  • Secure route according to roles
  • User can add role