Arcayne
Arcayne

Reputation: 1186

Parse.User.current() not giving back a user object

I am using Parse.com JS API. when using parse.user method

getCurrentUser: function getCurrentUser(callback)
        {
            var currentUser = Parse.User.current();
            callback(currentUser);
        }

That would give my back:

result of the code 1

So since I am really interested in the attributes of this object I need to do something like this:

getCurrentUser: function getCurrentUser(callback)
        {
            var currentUser = Parse.User.current();
            //Not quite sure why I need to do that but I fugre out I cannot not really get the user object without
            var userObject = new Object();

            userObject.nick =  currentUser.attributes.nick;
            userObject.gender =  currentUser.attributes.gender;
            userObject.favoriteGenre = currentUser.favoriteGenre;

            callback(userObject);
        }

Which seems to me a bit dirty way of doing it?

Is there a better way to overcome this obstacle?

Note that I am using the method Parse.User.current(); so I can save a call to parse.com and get the info from the local storage.

Thanks in advance!

EDIT:

I just saw I can use also:

Parse.User.current().get("nick");

Which seems cleaner, just make me think if I'll be in some case consuming my parse.com calls more than I want. Someone knows about that?

Upvotes: 1

Views: 3799

Answers (1)

Thomas Bouldin
Thomas Bouldin

Reputation: 3725

You are correct that "get" is the cleaner way. API calls are measured by client-server API calls. If you fetch the whole user object, that is one API call; if the user is loaded from localStorage it's none. Property access is a local operation that is free.

Upvotes: 2

Related Questions