I'm calling this function to retrieve a user attribute, however when i'm testing the function the return result is always "test" and then it goes through "cognitoUser.getUserAttributes" and logs the actual result. I'm not sure why but "cognitoUser.getUserAttributes" seems to be skipped initially.
when run, it prints out test and instead of the actual result
any ideas?
function retrieveattribute(e) {
var ans = "test";
var e = "custom:InstanceID_1";
cognitoUser.getUserAttributes(function(err, result) {
if (err) {
alert(err);
return;
}
for (i = 0; i < result.length; i++) {
if (result[i].getName() == e) {
ans = result[i].getValue();
console.log(ans);
return ans;
}
}
});
return ans;
}