Skip to content

Fixed: ParseUser.getCurrentUser() returns a non authenticated user when local datastore is used #3

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 18, 2015

Conversation

lukas1994
Copy link
Contributor

Repro project: https://www.dropbox.com/s/m6vl215mg3nj8uo/Parse-Starter-Project-1.9.4.zip
1- change keys
2- click SIGN UP
-> make sure a user & a post are created
3- click GETCURRENTUSER
-> make sure user and session are shown
4- click ISAUTHENTICATED()
-> make sure it returns true
5- now click QUERY DATA WITH INCLUDE("USER")
6- repeat step 3 and 4 and notice the issue

@grantland
Copy link
Contributor

I'm not convinced that this is where the actual problem lies, since we shouldn't be overwriting sessionToken when merging from LDS when the JSON isn't complete. Could you add some unit tests that reproduces the problem so I could see more into why this problem occurs?

@grantland grantland added needs revision type:bug Impaired feature or lacking behavior that is likely assumed labels Aug 13, 2015
@lukas1994
Copy link
Contributor Author

If the server returns the query that contains a reference to the currentUser the following happens:
The ParseDecoder calls ParseObject.fromJSON() with isComplete == true.
Then ParseObject.createWithoutData() gets called.
If the local datastore is enabled it gets currentUser from the store (by object id).
Finally, we call currentUser.mergeFromServer() with isComplete == true which overwrites currentUser with the data from the server (which doesn't contain the sessionToken, ...).

There are different ways to fix this. We need to add a special case somewhere: ParseUser is the best place I guess. Another fix would be to set isComplete == false appropriately.

What do you think?

@lukas1994
Copy link
Contributor Author

One interesting thing to note is that the server normally returns the sessionToken if you query for users but if you query for posts that contain a pointer to a user then it doesn't return the sessionToken.

@grantland
Copy link
Contributor

If that's the case, it seems like this current modification will have some unintended side affects such as stale data such as keys that were removed on the server persisting after a fetch.

We'd probably want to have a more precise fix that is conditional upon the ParseUser instancing being current and only persisting the sessionToken locally if there was no sessionToken in the new state.

Additionally, this should be verified with actual code that hits the server, but the PR should contain a unit test that prevents this from happening in the future.

@@ -501,6 +501,15 @@ private void restoreAnonymity(Map<String, String> anonymousData) {
}

@Override
void setState(ParseObject.State newState) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For future PRs, we use /* package */ to designate package protected methods.

@grantland
Copy link
Contributor

This is looking much better! Just an optimization and a few minor nits.

}
else {
super.setState(newState);
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This logic seems a tad messy, could we simplify it to the following?

if (/* ... */) {
  newState = // ...
}
super.setState(newState);

@grantland
Copy link
Contributor

Sorry, I realized that there are some additional use cases that we should cover in the tests.

…en local datastore is used

Repro project: https://www.dropbox.com/s/m6vl215mg3nj8uo/Parse-Starter-Project-1.9.4.zip
1- change keys
2- click SIGN UP
-> make sure a user & a post are created
3- click GETCURRENTUSER
-> make sure user and session are shown
4- click ISAUTHENTICATED()
-> make sure it returns true
5- now click QUERY DATA WITH INCLUDE("USER")
6- repeat step 3 and 4 and notice the issue
@grantland
Copy link
Contributor

Looks awesome, thanks!

Also same comments RE commits, etc. as I made on your other diff.

@grantland grantland removed their assignment Aug 18, 2015
lukas1994 added a commit that referenced this pull request Aug 18, 2015
Fixed: ParseUser.getCurrentUser() returns a non authenticated user when local datastore is used
@lukas1994 lukas1994 merged commit 5c59ea1 into parse-community:master Aug 18, 2015
@grantland grantland modified the milestone: 1.10.1 Aug 18, 2015
@atahir33 atahir33 mentioned this pull request Jan 7, 2016
@facebook-github-bot
Copy link

@lukas1994 updated the pull request.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type:bug Impaired feature or lacking behavior that is likely assumed
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants