1.0.8 • Published 5 years ago

express-protect-router v1.0.8

Weekly downloads
1
License
MIT
Repository
github
Last release
5 years ago

Express protect router with username, password

Features

  • Protect express router with username and password

Installation

yarn add express-protect-router

or

npm install express-protect-router --save

Basic Usage

import express from 'express';
import Protect from 'express-protect-router';

const app = express();

const protecter = new Protect({ // pass into your configuration
  username: 'username',
  password: 'password',
  isProtec: process.env.NODE_ENV === 'development' ? 1 : 0 , // you may want the route to be protected in different environments. For example protection on development and permission on producton
});

protecter.init(app);

app.get('/', protecter.requireAuth, (req, res) => {
  return res.status(200).json({ message: 'Welcome to protect router' });
});

app.listen(3000, () => {
  // eslint-disable-next-line no-console
  console.log(`
    Port: ${3000}
    Env: ${app.get('env')}
  `);
});

export default app;

Options

PropUsing with env varDefaultDescription
usernameUSER_NAME
passwordPASSWORD
issISS'thisisiss'Iss used to sign a token
expireEXPIRE60 60 24 (1 day)Expire time of token
secretSECRET'SESSION_SECRET'Secret key of token
isProtecPROTECTundefineIf isProtec is set to 0, authentication will be ignored
redirectTo'/'The router will redirect after authentication
htmlPath'static/login.html'Path of the html file rather than the authentication form
protectPath'/auth'The router sends up the credentials
productionDomainIf specified and a value not equal to req.headers.host will enable protection
1.0.8

5 years ago

1.0.7

5 years ago

1.0.6

5 years ago

1.0.5

5 years ago

1.0.4

5 years ago

1.0.3

5 years ago

1.0.1

5 years ago

1.0.0

5 years ago