Using javascript, after the user logs in successfully, I tried to extract the username as below:
var user = Parse.User.current();
name = user.getUsername;
The value of name is: function (){return this.get("username")}
If I use name = user.getUsername();
The value is undefined!!
user.fetch().then(function(fetchedUser){
var name = fetchedUser.getUsername();
}, function(error){
//Handle the error
});
Here the issue is Parse.User.current()
method will return a user object if the user logged in or signed up successfully, but this object wont be having all the details of the user object. In order to get all the object properties you have to call fetch
method on a user Object
.
try
var user = Parse.User.current();
var name= user.get("username");
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With