Parse: Facebook user unlink and login again create two entries in user table

I see that my logical login via Facebook code looks like this.

PFFacebookUtils.logInInBackgroundWithReadPermissions(permissions) {
        (user: PFUser?, error: NSError?) -> Void in
        if let user = user {
            if user.isNew {
                println("User signed up and logged in through Facebook!")
                let graphRequest : FBSDKGraphRequest = FBSDKGraphRequest(graphPath: "me", parameters: nil)
                graphRequest.startWithCompletionHandler({ (connection, result, error) -> Void in

                    if ((error) != nil)
                    {
                        println("Error: \(error)")
                    }
                    else
                    {
                        let userEmail : NSString = result.valueForKey("email") as! NSString
                        println("User Email is: \(userEmail)")
                        user["email"] = userEmail
                    }
                })
            } else {
                println("User logged in through Facebook!")
            }
        } else {
            println("Uh oh. The user cancelled the Facebook login.")
        }
    }

The exit method is as follows:

PFFacebookUtils.unlinkUserInBackground(PFUser.currentUser()!) { (succeeded: Bool, error: NSError?) -> Void in
        if succeeded {
            FBSDKAccessToken.setCurrentAccessToken(nil)
            FBSDKProfile.setCurrentProfile(nil)
            PFUser.logOut()
        } else {
            println("Error")
        }
    }

When a user logs in for the first time, I see that the parsing creates a row in the user table using authData pointing to Facebook. After logging out, this authData is erased.

The problem is when the user logs in again, parse creates another line and binds authData pointing to Facebook, is there any way to avoid this. I want to use the same line created earlier and the Facebook login link instead of creating several lines every time a user logs out and logs in.

, , , , , .

+4
1

facebook, :

if !PFFacebookUtils.isLinkedWithUser(user) {
  PFFacebookUtils.linkUserInBackground(user, withReadPermissions: nil, {
    (succeeded: Bool?, error: NSError?) -> Void in
    if succeeded {
      println("Woohoo, the user is linked with Facebook!")
    }
  })
}

Parse.com:

, , . , PFUser Facebook. Facebook .

+3

All Articles