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