I have a function below and i set username outside the function but I can get the value inside of it but not outside. Why is that? Example shown below. I am trying to print it outside or call it so it returns that value
var username
Auth.loggedInUser().then(function (user){
username = user.username
console.log(username) <--- this will print the username
});
console.log(username) <--- this will print undefined
Also if i try the below it returns a promise in console that isnt just the username
var username = Auth.loggedInUser().then(function (user){
return user.username
});
console.log(username) <--- this will Promise {$$state: Object}$$state: Object__proto__: Object
How can i go about just getting the raw username when calling it?