Parse.com can't get username from Parse.User.current?

Using javascript, after a successful login, I tried to extract the username, as shown below:

var user = Parse.User.current(); name = user.getUsername; 

Name Value: function (){return this.get("username")}

If I use name = user.getUsername();

Undefined value !!

+7
javascript promise
source share
2 answers
 user.fetch().then(function(fetchedUser){ var name = fetchedUser.getUsername(); }, function(error){ //Handle the error }); 

Here the problem is the Parse.User.current() method will return a user object if the user is logged in or registered successfully, but this object will not have all the details of the user object. To get all the properties of an object, you must call the fetch method on the Object user.

+17
source share

to try

 var user = Parse.User.current(); var name= user.get("username"); 
+5
source share

All Articles