kane-internal-user-data
v0.3.4
Published
Koa middleware to collect user infos from headers
Downloads
5
Maintainers
Readme
Kane Internal User Data
This Koa middleware will retrieve the user data from headers and add it in the ctx.state
object.
Requirements
You need to execute node
version 8
at least (async/await
).
Installation
# npm
npm install --save kane-internal-user-data
# yarn
yarn add kane-internal-user-data
Usage
This package will try to re-assemble the user data from headers (starting with x-user-*
) and add the resulting object to ctx.state
.
const Koa = require("koa");
const extractUserData = require("kane-internal-user-data");
const app = new Koa();
app
.use(extractUserData())
.use(ctx => {
/**
* If succeeded, the following User properties will be retrieved
*
* @typedef {Object} user
* @property {String} id
* @property {String} firstName
* @property {String} lastName
* @property {String} userName
* @property {String} email
* @property {Array.<Number>} roles
* @property {Array.<String>} permissions
* @property {Date} createdAt
* @property {Date} updatedAt
*/
if (ctx.state.user.firstName === "foo") {
// do stuff
}
});
Linting
Made using eslint
. To enforce rules to be applied, use yarn lint:fix
.
Testing
Simply invoke yarn test
.
Contributing
First, install the dependencies using yarn
:
yarn install --frozen-lockfile
Verify that your project is configured correctly by launching tests:
yarn test
Before you start coding make sure that you've read our CONTRIBUTING
guide!