{"action":"created","issue":{"url":"https://api.github.com/repos/rkusa/koa-passport/issues/82","repository_url":"https://api.github.com/repos/rkusa/koa-passport","labels_url":"https://api.github.com/repos/rkusa/koa-passport/issues/82/labels{/name}","comments_url":"https://api.github.com/repos/rkusa/koa-passport/issues/82/comments","events_url":"https://api.github.com/repos/rkusa/koa-passport/issues/82/events","html_url":"https://github.com/rkusa/koa-passport/issues/82","id":185590311,"number":82,"title":"koa 2 not handling unsuccessful login","user":{"login":"dagda1","id":118328,"avatar_url":"https://avatars.githubusercontent.com/u/118328?v=3","gravatar_id":"","url":"https://api.github.com/users/dagda1","html_url":"https://github.com/dagda1","followers_url":"https://api.github.com/users/dagda1/followers","following_url":"https://api.github.com/users/dagda1/following{/other_user}","gists_url":"https://api.github.com/users/dagda1/gists{/gist_id}","starred_url":"https://api.github.com/users/dagda1/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dagda1/subscriptions","organizations_url":"https://api.github.com/users/dagda1/orgs","repos_url":"https://api.github.com/users/dagda1/repos","events_url":"https://api.github.com/users/dagda1/events{/privacy}","received_events_url":"https://api.github.com/users/dagda1/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":15,"created_at":"2016-10-27T07:13:42Z","updated_at":"2016-11-16T06:29:27Z","closed_at":"2016-10-27T21:26:27Z","body":"I am confused as to what is the correct way to use koa-passport with koa 2.\n\nSo far I have my strategy defined like this:\n\n```\nimport Strategy from 'passport-local';\n\npassport.use('local', new Strategy({\n  usernameField: 'username',\n  passwordField: 'password'\n}, async (username, password, done) => {\n  try {\n    const user = await User.findOne({\n      username\n    });\n\n    if (!user) {return done(null, false)}\n\n    try {\n      const isMatch = await user.validatePassword(password);\n\n      if (!isMatch) {\n        return done(null, false)\n      }\n\n      done(null, user)\n    } catch (err) {\n      done(err)\n    }\n\n  } catch (err) {\n    return done(err)\n  }\n}))\n```\n\nAnd I have my auth route defined like this:\n\n```\nconst router = new Router();\n\nrouter.post('/', function(ctx, next) {\n  return passport.authenticate('local', function(err, user, info, status) {\n    console.dir(arguments.length);\n    if(user === false) {\n      console.log('it gets here but then........');\n      return ctx.throw(401);\n    }\n\n    const token = jwt.sign({ id: user.id }, config.token);\n\n    const response = user.toJSON()\n\n    delete response.password;\n    delete response.salt;\n\n    ctx.body = {token,user: response};\n    ctx.status = 201;\n  })(ctx, next)\n})\nexport default router;\n```\n\nThis appears to work fine for the successful login but appears to hang and then comes back with this response\n\n```\nEmpty reply from server\n```\n"},"comment":{"url":"https://api.github.com/repos/rkusa/koa-passport/issues/comments/260865259","html_url":"https://github.com/rkusa/koa-passport/issues/82#issuecomment-260865259","issue_url":"https://api.github.com/repos/rkusa/koa-passport/issues/82","id":260865259,"user":{"login":"dagda1","id":118328,"avatar_url":"https://avatars.githubusercontent.com/u/118328?v=3","gravatar_id":"","url":"https://api.github.com/users/dagda1","html_url":"https://github.com/dagda1","followers_url":"https://api.github.com/users/dagda1/followers","following_url":"https://api.github.com/users/dagda1/following{/other_user}","gists_url":"https://api.github.com/users/dagda1/gists{/gist_id}","starred_url":"https://api.github.com/users/dagda1/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dagda1/subscriptions","organizations_url":"https://api.github.com/users/dagda1/orgs","repos_url":"https://api.github.com/users/dagda1/repos","events_url":"https://api.github.com/users/dagda1/events{/privacy}","received_events_url":"https://api.github.com/users/dagda1/received_events","type":"User","site_admin":false},"created_at":"2016-11-16T06:29:27Z","updated_at":"2016-11-16T06:29:27Z","body":"If the try catch is removed then where is the Promise rejection handled?"}}
{"actor":{"display_login":"dagda1"}}