Skip to content

chunpu/koa-user

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Simple user module of koa

Installation

npm install koa-user

Example

var user = require('koa-user')
var koa = require('koa')
var app = koa()

function check(username, passwd) {
  // username & passwd are given from koa-user
  // check, always by db search
  return function(fn) {
    db.query('SELECT * from users where username=' + username, function(err, result) {
      if (!err && result.passwd === passwd) {
        fn(null, result)
        // the second arg expect to be the user object
        // just like {id: 100, name: 'myname', ...}
        // user will be bind on `this`
      } else {
        fn(err)
      }
    })
  }
}

app.use(user(check))

app.use(function* () {
  this.body = this.user // this.user is the result you given from check handler
})

app.listen(3000)

Todo

  • add setting cookie
  • add options

License

MIT

About

simple user module(login, check token) for koa

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published