parse-server icon indicating copy to clipboard operation
parse-server copied to clipboard

cannot modify user function for Facebook user

Open adamontherun opened this issue 10 years ago • 26 comments

In iOS, with a normal (i.e. signed up with username and password) parse user, the following works: [PFUser currentUser].username = @"newParseName"; [PFUser currentUser] save];

However, a user who authenticated via Facebook who performs

[PFUser currentUser].username = @"newFBName"; [PFUser currentUser] save];

will get the following error:

[Error]: cannot modify user function () { return this.data.objectId || this.query.objectId; } (Code: 206, Version: 1.12.0)

This 'cannot modify user function' error is returned for any changes you try to make to the current loggedin user when its a Facebook user.

adamontherun avatar Jan 31 '16 18:01 adamontherun

Got the same issue. This error also occurs when creating any objects in any classes. It just seems like the current user context is not set appropriately when a user is authenticated through facebook.

anthonylai avatar Jan 31 '16 23:01 anthonylai

I'm getting the same error with username/password login. It works fine right after the user signs in. But if the app is closed and reopened, it stops working.

ramymedhat avatar Feb 01 '16 02:02 ramymedhat

Interesting.. Okay, we need to track down the root of this.

gfosco avatar Feb 01 '16 05:02 gfosco

Same issue here, used the simple code to test it and got: POST http://localhost:8081/parse/classes/_User/9ihJFseG01 400 (Bad Request)

function initFacebookWithParse() { window.fbAsyncInit = function() { Parse.FacebookUtils.init({ appId: '1554770854736875', xfbml: true, version: 'v2.5' }); };

(function(d, s, id) {
    var js, fjs = d.getElementsByTagName(s)[0];
    if (d.getElementById(id)) {
        return;
    }
    js = d.createElement(s);
    js.id = id;
    js.src = "//connect.facebook.net/en_US/sdk.js";
    fjs.parentNode.insertBefore(js, fjs);
}(document, 'script', 'facebook-jssdk'));

}

var currentUser; function facebookLoginWithParse() { if (!currentUser) { Parse.FacebookUtils.logIn("email,public_profile", { success: function(user) { if (!user.existed()) { console.log("User signed up and logged in through Facebook!"); FB.api('/me?fields=name,email', function(response) { if (response.email) { user.set("email", response.email); } user.save(); }); } else { console.log("User logged in through Facebook!"); user.set("javaScriptLogin", true); //set anything to make sense on saving user.save(); } currentUser = user; }, error: function(user, error) { console.log(user); console.log(error); console.log("User cancelled the Facebook login or did not fully authorize."); } }); } else { Parse.User.logOut(); Parse.User.currentAsync().then(function(user) { currentUser = user; console.log("logged out"); }, function(error) { console.log("error"); console.log(error); });

}

}

Logging in with user and password seems to work ok and lets me modify user

jganzabal avatar Feb 01 '16 06:02 jganzabal

This happens because the server does not set the sessionToken of the user created by [PFUser become]. The server gets a session token, signs the user in and then returns the user without a valid session token. This happens in the handleMe() function in users.js. After fixing this I hit another brick but I haven't solved it yet. I will post more info as soon as I figure out a solution.

viktor-skarlatov avatar Feb 02 '16 14:02 viktor-skarlatov

Any news on this?

Spacelapp avatar Feb 03 '16 01:02 Spacelapp

Check #173 -> it's been merged Haven't tested it yet to see if that fixes the cannot modify user function issue

edvincandon avatar Feb 03 '16 09:02 edvincandon

Just tested the #173, works like a charm. Now able to update_User object without any errors. Note: I had to manually delete my _User and _Session schema for it to work properly.

Thanks @taylorstine !

edvincandon avatar Feb 03 '16 12:02 edvincandon

@edvincandon :+1:

taylorstine avatar Feb 03 '16 12:02 taylorstine

Thanks @taylorstine ! Worked for me too after deleting _User and _Session schema.

jganzabal avatar Feb 03 '16 15:02 jganzabal

this is resolved.

adamontherun avatar Feb 03 '16 23:02 adamontherun

This still seems to be an issue for me. If I log in with Facebook, every call returned is 'cannot modify user'. Unfortunately I cannot delete my schemas because the app is live. Is there any way to fix this? I even tried using Parse.Cloud.useMasterKey() in my user beforeSave cloud code, but the issue still occurs.

DrBeak1 avatar Mar 07 '16 01:03 DrBeak1

@DrBeak1 same issue - deleting _User and _Session didn't help either

ryderjack avatar Mar 07 '16 23:03 ryderjack

@ryderjack ya I'm finding there seems to be a lot of issues here. I posted more details about exactly what is happening for me here: https://github.com/ParsePlatform/parse-server/issues/880

Hoping to get some feedback from someone. I'm an obj-c/java dev with only a little bit of node experience but enough to be helpful I suspect.

DrBeak1 avatar Mar 08 '16 02:03 DrBeak1

i'm also having issues. it seems that my a new user is created via facebook every time I log in through facebook.. very frustrating.

cid2105 avatar Mar 08 '16 04:03 cid2105

@cid2105 did you see the other issue I posted (https://github.com/ParsePlatform/parse-server/issues/880)? I was able to get around the issue of multiple users being created for the same facebook account by removing any beforeSave cloud code for the User model. Are you using a beforeSave trigger?

Not that removing the beforeSave is a real solution, but knowing it plays a part in this could help decipher what is going on.

DrBeak1 avatar Mar 08 '16 04:03 DrBeak1

@DrBeak1 unfortunately, deleting the beforeSave triggers isnt an option for me. Although I can modify my facebook users now, signing in creates a new user each time. very frustrating...

cid2105 avatar Mar 09 '16 01:03 cid2105

@cid2105 , very strange. I'm having the opposite issue after removing beforeSave: no new users, but cannot modify current. Out of curiosity, what client are you using to modify/sign in? iOS, javascript, android, etc? Just to be thorough, I'm using parse 1.7.1, parse-server 2.1.4, and ios parse 1.12.0.

DrBeak1 avatar Mar 09 '16 04:03 DrBeak1

my issue disappeared after upgrading to parse-server 2.1.6

cid2105 avatar Mar 12 '16 03:03 cid2105

Had to upgrade Parse Server to 2.1.6 and destroy my _User and _Schema for it to work for allowing me to modify my user data after authenticating through Facebook.

mikepaggi avatar Mar 12 '16 16:03 mikepaggi