Parse.User.current() returns an object without custom user class functions

Hi guys,

I’m using a custom user class named User that has additional functions like postConstruct(). When I try to get the current user object using

user: User;
this.user = Parse.User.current();

the user object does not have the functions of my custom user class like postConstruct().

The call of this.user.postConstruct() leads to TypeError: this.user.postConstruct is not a function.

When I log the object I clearly see that it has no functions of my custom user class:

_objCount: 0
className: "_User"
id: "abcdefghij"

q Prototyp
_cleanupAuthData()
_isLinked(R)
_linkWith(R,P)
_logOutWith(R)
_logOutWithAll()
_preserveFieldsOnFetch()
_synchronizeAllAuthData()
_synchronizeAuthData(R)
_unlinkFrom(R,P)
_upgradeToRevocableSession(R)
authenticated()
constructor: function(R)
destroy()
fetch()
fetchWithInclude()
getEmail()
getSessionToken()
getUsername()
isCurrent()
isCurrentAsync()
linkWith(R,P)
logIn(R)
save()
setEmail(R)
setPassword(R)
setUsername(R)
signUp(R,P)
verifyPassword(R,P)

What am I doing wrong?

An interesting observation: When I reload the page right after the error above was thrown the postContsruct() function is called without any problems.

Thanks in advance.

Best regards
Valdes

It seems to me that the error is because the Parse.User.Current() object hasn’t downloaded all of its information. Ideally, before carrying out any operation, you should make sure that you have the most up-to-date user. Try doing a fetch before using your custom function postContsruct().

Hi @joaoduartemariucio,

Unfortunately a fetch did not help. A timeout of 10 seconds did not help too. I’m getting weird…
Any other ideas?

Best regards
Valdes

Did you register your subclass? Looks like a test that passed exists.

@dplewis yes, it is a very importanty, try it @valdes21

Hi @dplewis,

Thank you for your advice. My subclass was registered. Thanks to the code snippet you have provided I have noticed that after the registration of the subclass the subclass has to be used on log in, sign up and when getting the current user. I have adjusted all (Custom)User calls accordingly (for example I have interchanged Parse.User.current() with User.current()). After this adjustment I was able to get the right object and call its functions.

Thanks!

Best regards
Valdes