I would like to return user's phone number but what I got is [object Object]. Im thinking if it return the value before await is done.Here is my code.
//assume phone number is 12345678
async function user_attr() {
try{
const { attributes } = await Auth.currentAuthenticatedUser();
console.log(JSON.stringify(attributes.phone_number)); //output:12345678
return (JSON.stringify((attributes.phone_number)))
} catch (e) {
console.log(e);
}
}
console.log('return='+user_attr()) //output: return=[object Object]
console.log('return='+JSON.stringify(user_attr())) //output: return={"_U":0,"_V":0,"_W":null,"_X":null}
To output 12345678 so that i can access it outside async function. For example to show it in profile page,
<Text>phone_number</Text>
Any way to save phone number string into the a constant outside async funcition?