Red2678
Red2678

Reputation: 3297

Extending Parse.User

I am trying to extend the Parse.User object and am having issues when calling base object methods namely, login.

So I have the following code:

main.models.User = Parse.User.extend({
    className : 'User',
    defaults : {
        objectId : false,
        username : 'anonymous',
        emailVerified : false,
        createdAt : new Date(),
        updatedAt : new Date(),
        firstName : 'Anonymous',
        lastName : 'User'
    },
    name : function() {
        return this.firstName + ' ' + this.lastName;
    }
});

At some point further along in my code I do:

main.user = new main.models.User();

Then further along in my code I do try to do this:

var $form = $(form);
main.user.logIn($form.find('#txtUserEmail').val(), $form.find('#pwdPassword').val(), {
    success : function() {
        // Hide the modal window 
        main.modal.empty();
    },
    error : function(user, error) {
        // Show Error
        that.ui.errorMsg.toggleClass('hidden').find('span').html('Error: ' + error.code + ' ' + error.message);
    }
});

tl;dr - The Problem

The login request happens but is malformed, as in my network tab I see the XHR, but the request payload is the entire backbone object, not just the username or password I passed into the login method. I get a 400 bad request.

enter image description here

And the response is:

code: 201
error: "missing user password"

The Real Question

Can I extend the Parse.User object and be able to call the base objects methods just as I would when using the main Parse object?

Thanks!

Upvotes: 0

Views: 437

Answers (1)

Héctor Ramos
Héctor Ramos

Reputation: 9258

The class name for a Parse.User is "_User", not "User", to avoid any conflicts with regular classes named "User". Your extension is overwriting the class name - that may or may not be causing this issue.

Upvotes: 1

Related Questions