Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Parse.com unable to get username from Parse.User.current?

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!!

like image 413
Yvan Avatar asked Feb 12 '14 18:02

Yvan


2 Answers

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.

like image 126
Triode Avatar answered Nov 19 '22 23:11

Triode


try

var user = Parse.User.current();
var name= user.get("username");
like image 6
ghosty89 Avatar answered Nov 19 '22 21:11

ghosty89