I want to write a function that adds the params of an ldap server after checking if the binding with server is right otherwise the data won't get added in the db ; i have to use feathers js. I tried to write a couple of lines to validate the params before adding them to the db : const ldap=require("ldapjs"); but the problem is that when i do console.log(errors) inside and outside of ldap.bind function : i noticed that the result is only visible inside the function but not to the rest of the code ! I need it to be visible to the other parts as well so that I can use it , I want to know how to fix that.
this is the code and what the console.log has as a result.
module.exports = (ldapConnexion, mode = "create") => {
const errors = {
url_path: [],
browsingAccount: [],
password: [],
userSearchBase:[],
};
const client=ldap.createClient({url:ldapConnexion.url_path})
client.bind(ldapConnexion.browsingAccount,ldapConnexion.password,function(err){
if (err){errors.browsingAccount.push("unvalid credentials:"+err);console.log(err)}})
console.log(errors)
const hasErrors = Object.keys(errors).reduce(
(res, errorType) =>
res || (errors[errorType] && errors[errorType].length > 0),
false
);
return { errors, hasErrors };
}