{"action":"created","issue":{"url":"https://api.github.com/repos/ParsePlatform/parse-server/issues/880","repository_url":"https://api.github.com/repos/ParsePlatform/parse-server","labels_url":"https://api.github.com/repos/ParsePlatform/parse-server/issues/880/labels{/name}","comments_url":"https://api.github.com/repos/ParsePlatform/parse-server/issues/880/comments","events_url":"https://api.github.com/repos/ParsePlatform/parse-server/issues/880/events","html_url":"https://github.com/ParsePlatform/parse-server/issues/880","id":138891043,"number":880,"title":"beforeSave Parse.User: after facebook sign up clears attributes.","user":{"login":"DrBeak1","id":1033734,"avatar_url":"https://avatars.githubusercontent.com/u/1033734?v=3","gravatar_id":"","url":"https://api.github.com/users/DrBeak1","html_url":"https://github.com/DrBeak1","followers_url":"https://api.github.com/users/DrBeak1/followers","following_url":"https://api.github.com/users/DrBeak1/following{/other_user}","gists_url":"https://api.github.com/users/DrBeak1/gists{/gist_id}","starred_url":"https://api.github.com/users/DrBeak1/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/DrBeak1/subscriptions","organizations_url":"https://api.github.com/users/DrBeak1/orgs","repos_url":"https://api.github.com/users/DrBeak1/repos","events_url":"https://api.github.com/users/DrBeak1/events{/privacy}","received_events_url":"https://api.github.com/users/DrBeak1/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":10,"created_at":"2016-03-07T05:26:51Z","updated_at":"2016-03-10T04:11:10Z","closed_at":null,"body":"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.\r\n\r\nI'm running parse-server on heroku connected to mongoDB. All is well.\r\n\r\nI have a beforeSave setup so that when a new user is created I assign a few variables to them before saving to the db. \r\n\r\nWhen 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:\r\n\r\n```\r\nParse.Cloud.beforeSave(Parse.User, function(request, response) {\r\n         for (var k in request.object.attributes) {\r\n                console.log(k+\": \" + `request.object.attributes[k]);`\r\n         }\r\n        response.success(request.object);\r\n});\r\n```\r\n\r\n... where I'm not doing anything but logging the incoming attributes, all attributes are stripped except for the ones mentioned above.\r\n\r\nAnyone else seeing this issue? I'm using parse-server, heroku, mongoLab, and an iOS client.\r\n\r\n**ALSO:**\r\nIf 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.\r\n\r\n**More Research** (Edit: regarding this piece, had to access vars via object.attributes.email):\r\nIf I JSON.stringify(request), the vars do come into the beforeSave correctly:\r\n```\r\n{\"triggerName\":\"beforeSave\",\"object\":{\"email\":\"mymail@me.com\",\"username\":\"mymail@me.com\",\"firstName\":\"Harry\",\"lastName\":\"Houdini\",\"randomId\":\"61fa3xxxxxxxxxx\",\"objectId\":\"gIOxxxxxxx\"},\"master\":false,\"original\":{\"objectId\":\"gIOxxxxxxx\"}}\r\n```\r\nBut when I try to access the vars (request.object.email), I get nothing but undefined.\r\n\r\n**And More [2016-03-07, 10:36PM]:**\r\nLast 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:\r\n\r\n> [PFFacebookPrivateUtilities userAuthenticationDataFromAccessToken:result.token];\r\n\r\non 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?"},"comment":{"url":"https://api.github.com/repos/ParsePlatform/parse-server/issues/comments/194654294","html_url":"https://github.com/ParsePlatform/parse-server/issues/880#issuecomment-194654294","issue_url":"https://api.github.com/repos/ParsePlatform/parse-server/issues/880","id":194654294,"user":{"login":"DrBeak1","id":1033734,"avatar_url":"https://avatars.githubusercontent.com/u/1033734?v=3","gravatar_id":"","url":"https://api.github.com/users/DrBeak1","html_url":"https://github.com/DrBeak1","followers_url":"https://api.github.com/users/DrBeak1/followers","following_url":"https://api.github.com/users/DrBeak1/following{/other_user}","gists_url":"https://api.github.com/users/DrBeak1/gists{/gist_id}","starred_url":"https://api.github.com/users/DrBeak1/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/DrBeak1/subscriptions","organizations_url":"https://api.github.com/users/DrBeak1/orgs","repos_url":"https://api.github.com/users/DrBeak1/repos","events_url":"https://api.github.com/users/DrBeak1/events{/privacy}","received_events_url":"https://api.github.com/users/DrBeak1/received_events","type":"User","site_admin":false},"created_at":"2016-03-10T04:11:10Z","updated_at":"2016-03-10T04:11:10Z","body":"In any case - I really appreciate your attention, and appreciate you supporting the server framework.\r\n\r\nStepping back from everything and starting with what seems to be at the root of one of the issues: After facebook auth, the user is not updated on mongoDB - that is, the new session token and facebook auth data is not sent and stored. I can confirm this as true because immediately following a successful call to `logInInBackgroundWithReadPermissions` I try to fetch the users details `fetchInBackgroundWithBlock`. This results in: `Object not found. (Code: 101, Version: 1.12.0)`, which is either (a) object doesn't exist (which it definitely does) OR (b) invalid session token."}}