search.on('end') fires before the entry is found
See original GitHub issueI’m using ldapjs client libraries to connect to an Active Directory server, everything works if the login succeeds and the user is found, but only if there’s no search.on(‘end’) specified. If I ad the ‘end’ listener, then it gets called BEFORE the user is found, so when I try to return the response, it crashes the app.
THIS DOESN’T WORK
client.search('ou=users, dc=company, dc=com', opts, function(error, search) {
console.log('Searching.....');
search.on('searchEntry', function(entry) {
if (entry.object) {
userClient = ldap.createClient({url: config.ldap.url, timeout: 5000, connectTimeout: 10000});
userClient.bind(entry.object.dn, password, function(err) {
if (err == null) {
res.send({status: "OK", sessionID: sessionID});
} else {
res.send("FAIL - BAD LOGIN");
}
});
}
});
search.on('end', function(){
res.send("FAIL - not found");
});
THIS WORKS, BUT ONLY IF THE USER IS FOUND, IF NOT, APP CRASHES.
client.search('ou=users, dc=company, dc=com', opts, function(error, search) {
console.log('Searching.....');
search.on('searchEntry', function(entry) {
if (entry.object) {
userClient = ldap.createClient({url: config.ldap.url, timeout: 5000, connectTimeout: 10000});
userClient.bind(entry.object.dn, password, function(err) {
if (err == null) {
res.send({status: "OK", sessionID: sessionID});
} else {
res.send("FAIL - BAD LOGIN");
}
});
}
});
All I want to do is return a failed login if the user does not exist on the server. And also determine if the login attempt failed by the password.
Any help would be greatly appreciated.
Issue Analytics
- State:
- Created 7 years ago
- Reactions:3
- Comments:10 (4 by maintainers)
Top Results From Across the Web
A firefighter's guide to fireground search and rescue – Part 2
The mission of a search and rescue team in a fire situation is to find victims ... bypass before entry eliminates them from...
Read more >How do you detect the clearing of a "search" HTML5 input?
I found this answer on another post and it works perfect for me and only fires when the user clears the search box....
Read more >Michigan v. Clifford :: 464 U.S. 287 (1984)
On interlocutory appeal, the Michigan Court of Appeals found that no exigent ... (a) Where a warrant is necessary to search fire-damaged premises, ......
Read more >search warrant | Wex | US Law | LII / Legal Information Institute
A search warrant is a warrant signed by a judge or magistrate authorizing a law ... basement to find the cause of fire,...
Read more >Specify time modifiers in your search - Splunk Documentation
latest=now, Specify that the search starts or ends at the current time. ... 24 hours before the search is run, up to midnight;...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
here is how I did it. I have a login process as follow: search the LDAP and bind it. So either way I need the userObject or a null value to decide whether bind/search has failed:
I am using the latest version and res.end always returns null if it can’t find anything. I don’t really care if the search was successful as you can see. But the failed part always happens when the search fails. It’s unfortunate that in “search” the error is not the same as other functions:
Hope this helps.
I thought the same thing, but end fires before searchEntry even when there is a record found. I haven’t figured out a way to retrieve an login error with this library.