koa-login
Description
Use in conjunction with koa-auth-jwt.
This middleware can be used to provide a simple login endpoint in koa.
The jsonwebtoken package is used to create and sign JSON web tokens (JWT).
Your login form has to send name
and password
in the request body.
Installation
$ npm install koa-login
Usage
var login = ;var options = secret: processenvSECRET { /* The userProvider should find the user by name e.g. in the database. It should return a Promise which resolves to an object containing two properties: { hash: // hash value of the users password, user: // user object itself } */ return // TODO } { return name: username ; } { return id: userid ; }; // endpoint expects 'name' and 'password' inside 'this.request.body'router;
Example
Click here for an example usage of this package.
Options
All options are mandatory!
secret
string which will be used to sign the jwtuserProvider
function which takes a name and returns a Promise. The Promise should return an object containing two properties: hash & user. Hash is the hashed value of the users password and user the user object itself.publicDataProvider
function which takes the user object and returns an object containing public, unencrypted data which will be sent back to the logged in usertokenDataProvider
function which takes the user object and returns an object containing data which will be encrypted inside the token
Test
$ npm install -g mocha
$ mocha