A
A
Abc Edc2015-01-30 19:59:21
Node.js
Abc Edc, 2015-01-30 19:59:21

Why does a post request for this feature work 50/50?

app.post('/login', UserController.handlers.login);

login: function(req, res){
        var mail = req.body.mail;
        var password  = req.body.password;
        async.waterfall([
            function(callback){
                User.findOne({mail : mail}, callback );
            },
            function(user, callback){
                if (user){
                        if (user.checkPassword(password)){
                            req.session.user = user._id;
                            result= {"login":"yes"};
                        }
                        else{
                            result= {"login":"no"}
                        }
                    }
                else{
                        result = {"User": "notFound"};
                    }
                callback(null, result);
            }
        ], function (err, result) {
            res.json(result);
        });

I'm testing in different POST REQUEST ONLINE services and in half it works out, in half it doesn't, something seems to be with headers or something, how to do it universally so that it works?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
T
Timur Shemsedinov, 2015-01-31
@gleber1

Most likely this is because User.findOne({mail : mail}, callback); returns an error in callback and waterfall does not go further, i.e. the second function is not executed, but the final one is immediately called. It is not entirely clear what "does not work" means, what exactly is happening? Hangs and falls off on a timeout? What can be seen from the browser (firebug, developertools)? What http code returns or just breaks the connection? I advise you to form the result already in the final function, and only prepare data for this in the waterfall function array.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question