0.3.4 • Published 6 years ago

kane-internal-user-data v0.3.4

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

Kane Internal User Data

Build Status

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!

0.3.4

6 years ago

0.3.3

6 years ago

0.3.2

6 years ago

0.3.1

6 years ago

0.3.0

6 years ago

0.2.0

6 years ago