If I send a login request using the form fields action="/login", method="post"
, it works just fine. Similar to the code available here or here.
But if instead, if I send the same information using jquery/ajax
, then passport just doesn't seem to work. There is no actual login happening via passport, but the ajax call gives a misleading success message.
The below isn't working. Though I get "login success" message, login hasn't really happened.
$('#login_button').click(function () {
var email = $('#email').val();
var password = $('#password').val();
alert ('email/pass:' + email + ", " + password);
$.ajax({
type: "POST",
url: "/login",
data: { email: email , password: password },
dataType: 'html'
})
.done(function () {
console.log("http request succeeded");
alert("login success");
});
});
I need to use the ajax
method, so that I can do something useful on the client side, after successful login. E.g. start socket.io
.
Please help. My modified code is available here: my-modified-code