0

In the below code, if I remove event emitter part the function is working properly (only the commented code). With event emitter what Im doing wrong here? Im getting Error TypeError: Cannot set property 'undefined' of undefined

function mapDetail(username, password, oauthToken, callback) {
    var eventEmitter = new events.EventEmitter();
    eventEmitter.on('completed', function (message) {
        if (message != "false"); {
        /* var key;
        this.users[key] = {username: username, password: password}
        for (key in this.users) {
            if (this.users[key] && this.users[key].username == username && this.users[key].password == password) {
                // Update the oauthToken document to signal that key is authenticated
                for (var otherKey in this.oauth_users_request_tokens) {
                    if (this.oauth_users_request_tokens[otherKey] && this.oauth_users_request_tokens[otherKey].token == oauthToken) {
                        this.oauth_users_request_tokens[otherKey].authenticated = true;
                        callback(null, this.oauth_users_request_tokens[otherKey]);
                        return;
                    }
                }
            }
        } */
        }
        else
        callback(new Error("Authentication of user/password failed"), null);
    });
    LDAPObj.userDetails(username, password, eventEmitter);
}


LDAPObj.userDetails is the code from below link Node JS LDAP Auth User
In this code Im emitting the event in below scenarios On error eventEmitter.emit('completed',"false"); On success eventEmitter.emit('completed',"true");

4

0 回答 0