{"action":"created","issue":{"url":"https://api.github.com/repos/totaljs/framework/issues/232","labels_url":"https://api.github.com/repos/totaljs/framework/issues/232/labels{/name}","comments_url":"https://api.github.com/repos/totaljs/framework/issues/232/comments","events_url":"https://api.github.com/repos/totaljs/framework/issues/232/events","html_url":"https://github.com/totaljs/framework/issues/232","id":53843772,"number":232,"title":"Passport js Error: Can't render headers after they are sent to the client","user":{"login":"LeventeNagy","id":4026687,"avatar_url":"https://avatars.githubusercontent.com/u/4026687?v=3","gravatar_id":"","url":"https://api.github.com/users/LeventeNagy","html_url":"https://github.com/LeventeNagy","followers_url":"https://api.github.com/users/LeventeNagy/followers","following_url":"https://api.github.com/users/LeventeNagy/following{/other_user}","gists_url":"https://api.github.com/users/LeventeNagy/gists{/gist_id}","starred_url":"https://api.github.com/users/LeventeNagy/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/LeventeNagy/subscriptions","organizations_url":"https://api.github.com/users/LeventeNagy/orgs","repos_url":"https://api.github.com/users/LeventeNagy/repos","events_url":"https://api.github.com/users/LeventeNagy/events{/privacy}","received_events_url":"https://api.github.com/users/LeventeNagy/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":8,"created_at":"2015-01-09T08:17:16Z","updated_at":"2015-01-10T10:29:04Z","closed_at":null,"body":"So i took a look at the example, could not figure it out \r\n\r\nI made a passport.js file in my definitions\r\n\r\n<pre>\r\nvar passport = require('passport')\r\n  , LocalStrategy = require('passport-local').Strategy\r\n  , User = MODEL('user').schema\r\n  , bcrypt = require('bcryptjs');\r\n\r\n\r\n\r\npassport.serializeUser(function(user, done) {\r\n  done(null, user.id);\r\n});\r\n\r\npassport.deserializeUser(function(id, done) {\r\n  User.one({id: id}, function(err, user) {\r\n    done(err, user);\r\n  });\r\n});\r\n\r\n\r\npassport.use(new LocalStrategy({\r\n        usernameField: 'email',\r\n        passwordField: 'password'\r\n    },\r\n    function(email, password, done) {\r\n\t  \r\n    User.one({ email: email}, function(err, user) {\r\n\t    if (err) { return done(err); }\r\n\r\n\t    if (!user) { return done(null, false, { message: 'Unknown E-mail address ' + email }); }\r\n\r\n\t    if (user.password != password) { return done(null, false, { message: 'Invalid password' }); }\r\n\t    \r\n\t    return done(null, user);\r\n\t  });\r\n    }\r\n)); \r\n\r\n\r\nframework.middleware('passport.js', passport.initialize());\r\nframework.middleware('passport.js', passport.session());\r\n</pre>\r\n\r\nMy Controller \r\n\r\n<pre>\r\nexports.install = function(framework) {\r\n\tframework.route('/admin', view_admin);\r\n\tframework.route('/admin/login', view_login);\r\n\tframework.route('/admin/auth', auth, ['post', '#session', '#passport.js']);\r\n}\r\n</pre>\r\n\r\n<pre>\r\nfunction view_admin() {\r\n\tvar self = this;\r\n\r\n\tself.view('index')\r\n}\r\n\r\nfunction view_login() {\r\n\tvar self = this;\r\n\r\n\tself.view('login')\r\n}\r\n\r\nfunction auth() {\r\n\tvar self = this;\r\n\tpassport.authenticate('local')(self.req, self.res, function(err) {\r\n\t\tif (err)\r\n\t\t\treturn console.log(err);\r\n\r\n\t\t// self.json(self.user);\r\n\t\tself.json({ object: self.user });\r\n\t});\r\n\r\n}\r\n</pre>\r\n\r\nWhen i submit the form i get the following error\r\n\r\n<pre>\r\n====== 2015-01-09 09:11:08: Error: Can't render headers after they are sent to\r\nhe client. Error: Can't render headers after they are sent to the client.\r\n   at ServerResponse.OutgoingMessage._renderHeaders (http.js:731:11)\r\n   at ServerResponse.writeHead (http.js:1152:20)\r\n   at C:\\server\\apache2\\htdocs\\total\\node_modules\\total.js\\index.js:2:30593\r\n   at Gzip.onEnd (zlib.js:166:5)\r\n   at Gzip.emit (events.js:117:20)\r\n   at _stream_readable.js:943:16\r\n   at process._tickCallback (node.js:419:13)\r\n\r\n</pre>\r\n\r\nAm i missing something? Is there a middleware for http? or im doing it wrong?\r\n\r\nThank you"},"comment":{"url":"https://api.github.com/repos/totaljs/framework/issues/comments/69451205","html_url":"https://github.com/totaljs/framework/issues/232#issuecomment-69451205","issue_url":"https://api.github.com/repos/totaljs/framework/issues/232","id":69451205,"user":{"login":"LeventeNagy","id":4026687,"avatar_url":"https://avatars.githubusercontent.com/u/4026687?v=3","gravatar_id":"","url":"https://api.github.com/users/LeventeNagy","html_url":"https://github.com/LeventeNagy","followers_url":"https://api.github.com/users/LeventeNagy/followers","following_url":"https://api.github.com/users/LeventeNagy/following{/other_user}","gists_url":"https://api.github.com/users/LeventeNagy/gists{/gist_id}","starred_url":"https://api.github.com/users/LeventeNagy/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/LeventeNagy/subscriptions","organizations_url":"https://api.github.com/users/LeventeNagy/orgs","repos_url":"https://api.github.com/users/LeventeNagy/repos","events_url":"https://api.github.com/users/LeventeNagy/events{/privacy}","received_events_url":"https://api.github.com/users/LeventeNagy/received_events","type":"User","site_admin":false},"created_at":"2015-01-10T10:29:04Z","updated_at":"2015-01-10T10:29:04Z","body":"Okay will do"}}