I am attempting to retrieve a result from a series of callback functions, but I am encountering an issue where no result is being returned at all.
Below is the code snippet I am working with:
Main function :
let userldap:userLDAP = {controls:[],objectClass:[],dn:"",sn:"",givenName:"",mail:"",uid:"",cn:"",userPassword:""};
let res:ldapRes = {err:"",info:"",user:userldap};
this.ldap.authentication(credentials,res);
Essentially, I am trying to modify the values in the `res` object.
Service :
public authentication(
credentials: Credentials,
res:ldapRes,
):void {
this.ldap.authenticate(credentials.username, credentials.password,function(err:string,user:any,info:string) {
res.err = err;
res.info=info;
res.user=user;
});
}
This appears to be a very basic usage scenario. However, the callback within the `authenticate` function does not seem to update the `res` object.
I have tried several approaches such as using global context, but the callback in the `authenticate` function continues to reset the object to its original value after modification.
If anyone has insight into what may be causing this issue (it appears to be a simple problem related to variable scope, although I am unable to find a solution), I would greatly appreciate your input :) .
Thanks.
EDIT : Despite attempts including using `await` on the callback within the `auth` function, the issue persists:
public async authentication(credentials : Credentials, res: ldapRes):Promise<ldapRes>{
//console.log(res);
await this.ldap.authenticate(credentials.username, credentials.password, function(err:string,user:any,info:string) {
res.err = err; res.info=info; res.user = user;
console.log("Callback from inside auth function :");
console.log(res);
});
console.log("Callback from outside auth function :");
console.log(res);
return res;
}
In this case, the logging within the function works as expected, while the external log still displays a reset version of `res` (no values).