title: Koa and Passport with MongoDb
body: <p>I'm having some troubles with Koa, Passport and Monk.</p>
  
  <p>I'd like to have a simple local authentication with Passport. I've followed some tutorials and got as far as this: (auth.js)</p>
  
  <pre><code>const
    passport = require('koa-passport'),
    LocalStrategy = require('passport-local').Strategy,
    monk = require('monk'),
    wrap = require('co-monk'),
    db = monk('localhost/try'),
    users = wrap(db.get('users'));
  
  var user = {
    id: 1,
    username: 'test'
  };
  
  passport.serializeUser(function(user, done) {
    done(null, user.id);
  });
  
  passport.deserializeUser(function(id, done) {
    done(null, user);
  });
  
  passport.use(new LocalStrategy(
    function(username, password, done) {
  
      if (username === 'test' &amp;&amp; password === 'test') {
  
        return done(null, user);
      } else {
        return done(null, false);
      }
  
    }
  
  ));
  
  module.exports = passport;
  </code></pre>
  
  <p>Now this works ok, but how can I use my MongoDb database here instead of if (username === 'test' &amp;&amp; password === 'test')?</p>
  
  <p>I've tried to add this function:</p>
  
  <pre><code>function *getUser(name) {
    var useri = yield users.find({name:name});
    return useri;
  };
  </code></pre>
  
  <p>and then use it like this:</p>
  
  <pre><code>passport.use(new LocalStrategy(
    function(username, password, done) {
  
      var useri = getUser(username);
      console.log(useri);
  
      if (username === 'test' &amp;&amp; password === 'test') {
  
        return done(null, user);
      } else {
        return done(null, false);
      }
    }
  ));
  </code></pre>
  
  <p>but only end up getting {} in my console.</p>
  
  <p>So how do I do this? It's all so easy in Express but with this Koa thingy I'm really struggling to understand how it all works..</p>