Skip to content

Conversation

Vortec4800
Copy link

This is a fix for the issue identified in #963.

If the _currentUser object is set early on before a custom user subclass has been registered, it will never be updated with the subclassed user. As the current user loading is asynchronous this can create a race condition, and for some app launches currentUser() will return a PFUser and other times it will return your custom subclass.

This adds a check to verify that the cached user object is of the class that we expect to get. If it isn't, it continues with user loading which will create the correct class.

This all means that currentUser() will return a PFUser before the user subclass is registered, and a MYUser custom subclass after the registration completes. This seems like expected behavior and should prevent hard to track down bugs, especially in Swift projects where the + load method isn't available.

As an aside, it seems this issue may also be fixed by the merging of #5. That has been sitting around for a long time, and this PR should get us by until that old PR can be evaluated and merged.

if (currentUser) {
// Verify that the current user matches our expected registered subclass
Class expectedClass = [[PFObjectSubclassingController defaultController] subclassForParseClassName:@"_User"];
if(expectedClass == [currentUser class]){
Copy link
Contributor

Choose a reason for hiding this comment

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

We probably should do [currentUser isKindOfClass:expectedClass] here instead of direct class comparison.

@Vortec4800
Copy link
Author

Probably a good idea. I've been working in Swift too much lately. :D

@nlutsenko
Copy link
Contributor

Let's continue the discussion on the linked issue. This looks good and I love the idea, but not sure whether a temporary patch is the right solution.

@Vortec4800
Copy link
Author

Updated as requested, in case we decide to use this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants