{"action":"closed","issue":{"url":"https://api.github.com/repos/ga-dc/project3/issues/45","labels_url":"https://api.github.com/repos/ga-dc/project3/issues/45/labels{/name}","comments_url":"https://api.github.com/repos/ga-dc/project3/issues/45/comments","events_url":"https://api.github.com/repos/ga-dc/project3/issues/45/events","html_url":"https://github.com/ga-dc/project3/issues/45","id":121043978,"number":45,"title":"User Authentication & Login using Ajax Requests","user":{"login":"beckybeauchamp1","id":10798030,"avatar_url":"https://avatars.githubusercontent.com/u/10798030?v=3","gravatar_id":"","url":"https://api.github.com/users/beckybeauchamp1","html_url":"https://github.com/beckybeauchamp1","followers_url":"https://api.github.com/users/beckybeauchamp1/followers","following_url":"https://api.github.com/users/beckybeauchamp1/following{/other_user}","gists_url":"https://api.github.com/users/beckybeauchamp1/gists{/gist_id}","starred_url":"https://api.github.com/users/beckybeauchamp1/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/beckybeauchamp1/subscriptions","organizations_url":"https://api.github.com/users/beckybeauchamp1/orgs","repos_url":"https://api.github.com/users/beckybeauchamp1/repos","events_url":"https://api.github.com/users/beckybeauchamp1/events{/privacy}","received_events_url":"https://api.github.com/users/beckybeauchamp1/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"milestone":null,"comments":13,"created_at":"2015-12-08T16:25:52Z","updated_at":"2015-12-09T00:08:51Z","closed_at":"2015-12-09T00:08:51Z","body":"I am trying to submit a post request through AJAX from a form to login Users from the client side without having a page refresh. My request for User.postLogin is failing each time, as I believe it has something to do with my middleware calls to set a session. Is there a way I can do this using Passport and Ajax, or would I have to hand roll my user authentication in order for this to work? \r\n\r\nAny help would be greatly appreciated, I am really interested to know a potential solution!! \r\n\r\nHere is my code and specifically my ajax requests from client side:\r\n```js\r\nUser.post = function(){\r\n  var self = this;\r\n  var url = \"http://localhost:3000/signup\";\r\n  var request = $.ajax({\r\n    url: url,\r\n    type: \"POST\",\r\n    dataType: \"json\",\r\n    data: {\r\n      firstname: $(\"#firstname\").val(),\r\n      lastname: $(\"#lastname\").val(),\r\n      email: $(\"#email\").val(),\r\n      password: $(\"#password\").val()\r\n    }\r\n  }).then(function(postedUserinfo){\r\n    self.reload(postedUserinfo);\r\n  });\r\n  return request;\r\n};\r\n\r\nUser.postLogin = function(){\r\n  var self = this;\r\n  var url = \"http://localhost:3000/login\";\r\n  var request = $.ajax({\r\n    url: url,\r\n    type: \"POST\",\r\n    dataType: \"json\",\r\n    data: {\r\n      firstname: $(\"#firstname\").val(),\r\n      lastname: $(\"#lastname\").val(),\r\n      email: $(\"#email\").val(),\r\n      password: $(\"#password\").val()\r\n    }\r\n  }).then(function(res){\r\n    alert(\"sucess user!\");\r\n  }).fail(function(res){\r\n    console.log(res);\r\n    alert(\"failure from user post\");\r\n  });\r\n};\r\n```\r\n\r\nMy users routes:\r\n```\r\nvar passport = require(\"passport\");\r\n\r\nvar usersController = {\r\n  getSignup: function(req, res){\r\n    res.json({message: 'get request from signup'});\r\n    res.render('/');\r\n  },\r\n  postSignup: function(req, res){\r\n    var signUpStrategy = passport.authenticate('local-signup', {\r\n      successRedirect: '/',\r\n      failureRedirect: '/signup',\r\n      failureFlash: true\r\n    });\r\n\r\n    return signUpStrategy(req, res);\r\n  },\r\n  getLogin: function(req, res) {\r\n    res.render('/');\r\n  },\r\n  postLogin: function(req, res) {\r\n    console.log(\"Route being hit\");\r\n    var loginProperty = passport.authenticate('local-login', {\r\n      successRedirect : '/',\r\n      failureRedirect : '/',\r\n      failureFlash : true\r\n    });\r\n    console.log(global.currentUser);\r\n    return loginProperty(req, res);\r\n  },\r\n  getLogout:  function(req, res) {\r\n    req.logout();\r\n  },\r\n};\r\n\r\nmodule.exports = usersController;\r\n```\r\n\r\nThank you so much!"}}