8

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

1
  • In the first case, you're just retrieving the function and not executing it. In the second case, you are properly executing the function, but it looks like the properties for the user haven't been populated yet. Commented Feb 12, 2014 at 18:29

2 Answers 2

19
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.

Sign up to request clarification or add additional context in comments.

1 Comment

thanks so much for sharing this. I have spent 14 hours looking for the answer!
6

try

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

1 Comment

Wrong place though :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.