Skip to content

beforeSave Parse.User: after facebook sign up clears attributes. #880

Closed
@DrBeak1

Description

@DrBeak1

I've been trying to get this to work for two days and can't seem to get things correct, so I suspect there is a bug somewhere.

I'm running parse-server on heroku connected to mongoDB. All is well.

I have a beforeSave setup so that when a new user is created I assign a few variables to them before saving to the db.

When I sign up via Facebook the beforeSave function is called, but all of the user object data is stripped except for ACL, updatedAt, createdAt, and username (which is a random string because of sign up via Facebook). The users auth data does not make it through and is therefore lost. Then if I sign up again using the same Facebook account, instead of logging in, it creates a brand new user. I've found that I can fix this issue by removing the beforeSave. With no beforeSave the auth data makes it to the database and future login attempts connect me to that previously created user (instead of creating new users each time). However, even with a beforeSave that is simply:

Parse.Cloud.beforeSave(Parse.User, function(request, response) {
         for (var k in request.object.attributes) {
                console.log(k+": " + `request.object.attributes[k]);`
         }
        response.success(request.object);
});

... where I'm not doing anything but logging the incoming attributes, all attributes are stripped except for the ones mentioned above.

Anyone else seeing this issue? I'm using parse-server, heroku, mongoLab, and an iOS client.

ALSO:
If I bypass the beforeSave, successfully creating the user - any time I try to modify the users attributes, I get an error "cannot modify user <objectId>", where <objectId> is the id of the user who is supposedly logged in.

More Research (Edit: regarding this piece, had to access vars via object.attributes.email):
If I JSON.stringify(request), the vars do come into the beforeSave correctly:

{"triggerName":"beforeSave","object":{"email":"[email protected]","username":"[email protected]","firstName":"Harry","lastName":"Houdini","randomId":"61fa3xxxxxxxxxx","objectId":"gIOxxxxxxx"},"master":false,"original":{"objectId":"gIOxxxxxxx"}}

But when I try to access the vars (request.object.email), I get nothing but undefined.

And More [2016-03-07, 10:36PM]:
Last one for tonight. I can see that auth data is being returned by Facebook after login via FB. I can confirm this by modifying the PFFacebookMobileAuthenticationProvider.m file to log the data returned from:

[PFFacebookPrivateUtilities userAuthenticationDataFromAccessToken:result.token];

on line 62 of that file. I can also see that after this login, that the access_token logged here does not match the access_token stored on my user in mongoDB, so this information is never being updated in the db. Clearly this is an issue. Now, why?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions