Skip to content

Error when setting currentUser().email to nil #1762

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

Closed
mtrezza opened this issue May 11, 2016 · 1 comment
Closed

Error when setting currentUser().email to nil #1762

mtrezza opened this issue May 11, 2016 · 1 comment

Comments

@mtrezza
Copy link
Member

mtrezza commented May 11, 2016

Environment Setup

  • Client: Parse SDK iOS 1.13.0 on iOS 9.3.1
  • Server: parse-server version 2.2.9, remote on heroku
  • Database: remote on mlab

Steps to reproduce

  1. login new user via Facebook with PFFacebookUtils.logInInBackgroundWithReadPermissions.
  2. retrieve the email address from the user's Facebook profile and set it as the user's email.
  3. given that the email address is already taken by an existing user the save attempt fails with error
  4. setting the user's email address to nil and trying again to save it results in error _this7.data.email.match is not a function (Code: 0, Version: 1.13.0)
  5. subsequently, all following attempts to save PFUser.currentUser() fail with the error above. When not setting the email property to nil all subsequent attempts fail with error PFErrorCode.ErrorUserEmailTaken.
PFFacebookUtils.logInInBackgroundWithReadPermissions(permissions) {
    (user: PFUser?, error: NSError?) in

    guard let user = user else {
            return
    }

    FBSDKGraphRequest(graphPath: "me", parameters: ["fields": "email"]).startWithCompletionHandler() {
        (connection: FBSDKGraphRequestConnection!, result: AnyObject?, error: NSError?) in

        guard let result = result where error == nil else {
            return
        }

        let email = result.valueForKey("email") as? String
        user.email = email

        user.saveInBackgroundWithBlock() {
            (succeeded: Bool, error: NSError?) in

            if let error = error where error.code == PFErrorCode.ErrorUserEmailTaken.rawValue {

                user.email = nil
                user.saveInBackground()
            }
        }
    }
}

Is this a bug on the server side?
How can the PFUser.currentUser().email property be reset?

Update
.removeObjectForKey("email") instead of setting the .email = nil leads to error {"code":1,"message":"Internal server error."} (Code: 1, Version: 1.13.0)

@mtrezza
Copy link
Member Author

mtrezza commented May 11, 2016

So the solution is to use user.revertObjectForKey("email") instead of user.email = nil. See issue "Update users Email in Parse #51" in Parse iOS SDK.

However I could not find revertObjectForKey in the docs, maybe that should be added.

@mtrezza mtrezza closed this as completed May 11, 2016
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

No branches or pull requests

1 participant