Parse-sdk-js: Parse.User.logIn or UserSubclass.logIn does not return a subclass instance

Created on 25 Apr 2016  路  8Comments  路  Source: parse-community/Parse-SDK-JS

    class CustomUser extends ParseUser {
      customMethod() {
        return 'a';
      }
    }
    ParseObject.registerSubclass(ParseUser.className, CustomUser);
    CustomUser.logIn('username', 'password').then((u) => {
      expect(u instanceof CustomUser).toBe(true);
      expect(u.customMethod()).toBe('a');
    });

Failing test case:
https://github.com/drinklynk/Parse-SDK-JS/commit/0a9fa9cfeee1dd9d2e47a356849ee67ae161e97a

bug

Most helpful comment

I found a way to do it

let user = new MyCustomUserClass;
user.username = 'johndoe';
user.password = 'secret';
user.logIn(null).then(obj => {
/// obj is an instance of MyCustomUserClass

All 8 comments

Interesting. Seems like rather than instantiating a new ParseUser directly, we want to use the className approach and create a new ParseObject('_User').
This might get a little tricky with the user class rewrite flag, but I'll look into this.

Same problem seems to exist with User.become

Any workaround for this issue?

This hasn鈥檛 been addressed yet, but further investigation would be appreciated

I found a way to do it

let user = new MyCustomUserClass;
user.username = 'johndoe';
user.password = 'secret';
user.logIn(null).then(obj => {
/// obj is an instance of MyCustomUserClass

Thanks fmendoza, this workaroud is really helpfull.

This workaround seems to no longer work with parse server v3 as we get username/email is required, @fmendoza can you confirm?

Still working on my end with Parse Server v3 and Parse SDK JS 2.1

Was this page helpful?
0 / 5 - 0 ratings

Related issues

futureinapps picture futureinapps  路  3Comments

marktyers picture marktyers  路  3Comments

anhhtz picture anhhtz  路  3Comments

bezi picture bezi  路  4Comments

dblythy picture dblythy  路  4Comments