{"action":"opened","issue":{"url":"https://api.github.com/repos/vtrofin/takezo/issues/15","repository_url":"https://api.github.com/repos/vtrofin/takezo","labels_url":"https://api.github.com/repos/vtrofin/takezo/issues/15/labels{/name}","comments_url":"https://api.github.com/repos/vtrofin/takezo/issues/15/comments","events_url":"https://api.github.com/repos/vtrofin/takezo/issues/15/events","html_url":"https://github.com/vtrofin/takezo/issues/15","id":306209415,"number":15,"title":"passport js - reorganizing the code in auth config files","user":{"login":"vtrofin","id":18513968,"avatar_url":"https://avatars1.githubusercontent.com/u/18513968?v=4","gravatar_id":"","url":"https://api.github.com/users/vtrofin","html_url":"https://github.com/vtrofin","followers_url":"https://api.github.com/users/vtrofin/followers","following_url":"https://api.github.com/users/vtrofin/following{/other_user}","gists_url":"https://api.github.com/users/vtrofin/gists{/gist_id}","starred_url":"https://api.github.com/users/vtrofin/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/vtrofin/subscriptions","organizations_url":"https://api.github.com/users/vtrofin/orgs","repos_url":"https://api.github.com/users/vtrofin/repos","events_url":"https://api.github.com/users/vtrofin/events{/privacy}","received_events_url":"https://api.github.com/users/vtrofin/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":0,"created_at":"2018-03-18T03:11:04Z","updated_at":"2018-03-18T03:11:04Z","closed_at":null,"author_association":"OWNER","body":"For now I've kept all my passport js related configuration in the server.js file. It looks like this. \r\nhttps://github.com/vtrofin/takezo/blob/070429e54b89657134d8735a02ffed670309aca8/server.js#L48-L79\r\n\r\nI have some difficulties in properly moving the configuration into a separate file and the importing it back into the code. I've seen this example https://github.com/gerges-beshay/oauth2orize-examples and they seem to just require the config functions inline, something like this:\r\n```js\r\n./server.js\r\n\r\n// Passport configuration\r\nrequire('./auth');\r\n\r\n```\r\n\r\nand then  in\r\n```js\r\n./auth.js\r\npassport.use(new LocalStrategy(\r\n  (username, password, done) => {\r\n    db.users.findByUsername(username, (error, user) => {\r\n      if (error) return done(error);\r\n      if (!user) return done(null, false);\r\n      if (user.password !== password) return done(null, false);\r\n      return done(null, user);\r\n    });\r\n  }\r\n));\r\npassport.serializeUser((user, done) =>  done(null, user.id));\r\npassport.deserializeUser((id, done) => {\r\n  db.users.findById(id, (error, user) => done(error, user));\r\n});\r\n```\r\n\r\nShould I just do the same? just throw a require() in the server.js file and be done with it? Is this the right way?"}}
{"actor":{"display_login":"vtrofin"}}