When working with amazon-cognito-identity-js, I encountered an issue with the callback function. This is what it currently looks like:
cognitoUser?.getUserAttributes((err, results) => {
if (err) {
console.log(err.message || JSON.stringify(err));
return err.message || JSON.stringify(err);
}
if (results != undefined) {
return results[2].Value;
}
return undefined;
});
Although I am able to successfully log the correct value from results[2], I am struggling to return this value. I attempted to use util-promisify, but unfortunately this npm package is intended for Webpack and not suitable for my Angular application. How can I implement a Promise instead?
Here is the declaration for getUserAttributes():
public getUserAttributes(
callback: NodeCallback<Error, CognitoUserAttribute[]>
): void;