Yvan
Yvan

Reputation: 271

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

Upvotes: 8

Views: 8774

Answers (2)

Triode
Triode

Reputation: 11359

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.

Upvotes: 19

ghosty89
ghosty89

Reputation: 86

try

var user = Parse.User.current();
var name= user.get("username");

Upvotes: 6

Related Questions