node-ldapjs: Possible bug - client.bind causing client to reload

Hi! I’m writing a page to reset user’s LDAP password. I’ve started with a simple form asking to provide an email address. Here I’m experiencing a problem: everything is working fine if a user submits email address only once, but if the user makes a mistake and have to re-submit the corrected email address my browser refreshes the page and the client cannot receive server’s response. I’ve debugged this step by step and found that client refreshes right after client.bind statement and doesn’t cause failure, the script continues the execution. Here is my code:

 var tlsOptions = { "ejectUnauthorized" false }
    client = ldap.createClient({
        url: ldapURL,
        tlsOptions: tlsOptions
    });

    client.bind( bindUser, bindPsw, function( err ) {
            
        if (err){
            logger.error("***Bind failed: " + err.message);
            res.status(500).send(err.message);
            return;
        }

        client.search( suffix, {filter:`(mail=${userEmail})`, scope:"sub"},
            (err, searchRes) => {
                ....
            
            });
                searchRes.on('error', function(err) {
                    console.error('error: ' + err.message);
                    res.status(500).send(err.message);
                });
                searchRes.on('end', function(result) {
                    if (!successSearchFlag){
                        res.status(500).send("User's email not found");
                        // console.log('End search status: ' + result.status);
                    }

            });
        });`

About this issue

  • Original URL
  • State: closed
  • Created 4 years ago
  • Comments: 17 (10 by maintainers)

Most upvoted comments

Just wanted to update: in my case GET request was sent by form itself. By default form sends GET requests, so together with my ajax request, form was sending also. I’ve resolved it by stopping the GET:

$("#emailForm").bind("submit", function(e) {
     e.preventDefault();
     e.stopImmediatePropagation();
});