npm.io
0.0.2 • Published 8 years ago

@wdalmut/mini-auth

Licence
MIT
Version
0.0.2
Deps
0
Size
2 kB
Vulns
0
Weekly
0

Express mini auth middleware

npm install --save @wdalmut/mini-auth

A simple auth middleware to simplify the authentication layer

const auth = require('mini-auth');
app.get("/", auth(all), homePage);

Allow

to create a authentication method just prepare a function that returns a promise.

let all = () => {
    return Promise.resolve({
        id: 1,
        username: "wdalmut",
    });
};

The promise information will be propagated to the application in the req.user field.

Deny

If the promise will be rejected the auth layer fails and will reply with 401.

let deny = () => {
    return Promise.reject({
        error: "no body in here",
    });
};