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);
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.
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",
});
};