0.0.2 • Published 5 years ago

express-box-auth v0.0.2

Weekly downloads
-
License
ISC
Repository
-
Last release
5 years ago

Express Auth In A Box

Introduction

Don't ever use this in production. It is strictly for dictactic/research purposes.

Just:

  • init an express app
  • npm i express_auth_box
  • const { handler } = require('express_auth_box')
  • and mount the handler as middleware: app.use(handler

Out of the box(!) you get /auth/login/, /auth/register/, and /auth/verify/ routes!

Yay!

Example

Here is an example server app with both public and private routes:

const express = require('express');
const bodyParser = require('body-parser');
const cors = require('cors');
const logger = require("morgan");
const app = express();

const { handler, restrict } = require('./box_auth');

app.use(logger('dev'));
app.use(cors());
app.use(bodyParser.json());

const router = express.Router();
router.get('/foo', (req, res) => res.json('ok'));
router.use(handler);
router.get('/secret', restrict, (req, res) => res.send('the answer is 42'));

app.use('/api', router);

module.exports = {
  app,
};