0

I am trying to get a user by objectId created in parse. After that, update that object by incrementing particular key. in this case "votes"

I have tried the following code, and it succesfully gets the object then cast it to PFUser for updating but it throws an error during save in background claiming that the user has to be logged in or signed up yet it already has that user?

Thanks for your help.

        var sender = self.mObject["sender"] as PFUser
        var senderObjId = sender.objectId

        println(senderObjId) //prints sender user object id
        //query the user
        var query = PFUser.query()
        query.getObjectInBackgroundWithId(senderObjId, block: { (object: PFObject!, error: NSError!) -> Void in

            let user : PFUser = object as PFUser
            user.incrementKey("votes")
            user.saveEventually({ (success: Bool!, error: NSError!) -> Void in
                println(success)
            })
        })

SPECIFIC ERROR RECEIVED:

"NSInternalInconsistencyException" with reason "User cannot be saved unless `they have been authenticated via logIn or signUp":`
Ronny K
  • 3,641
  • 4
  • 33
  • 43

1 Answers1

0

You're not logged in with the account which you want to edit. You can only edit the current account and not any account in the PFUser table. That's what I found on parse:

Security For User Objects

The PFUser class is secured by default. Data stored in a PFUser can only be modified by that user. By default, the data can still be read by any client. Thus, some PFUser objects are authenticated and can be modified, whereas others are read-only.

Specifically, you are not able to invoke any of the save or delete methods unless the PFUser was obtained using an authenticated method, like logIn or signUp. This ensures that only the user can alter their own data.

See this how to log in.

siegy22
  • 4,295
  • 3
  • 25
  • 43