Im trying to get a front end login form to work over ajax and running into issues, it seems to always pass back success and not sure how to actual make sure the cookie gets created and the user is logged in?

here is the gist of what i have right now: https://gist.github.com/keithmancuso/29e8446ec5fa66fb2b01

2 Answers 2


If you’re getting the {success: true} response, then the user is getting logged in successfully, and the cookie would have actually been created by that response.


I had a same problem and I will try to give you more detailed explanation.

Craft thinks you submitted a classic login form and Users controller tries to redirect you after successful login. In case you send AJAX request Craft will return success:true. So, you should add dataType: "json" in your AJAX request and you will be logged in with response success:true.

All in all, your code should be:

$('#loginForm').on('submit', function(e) {
        var formData = $(this).serialize();

            url: '/',
            contentType: "application/x-www-form-urlencoded",
            dataType: "json",
            data: formData,
            success: function(result) {

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.