diff --git a/src/Parse/ParseUser.php b/src/Parse/ParseUser.php index 32ebeb17..2c31cd31 100644 --- a/src/Parse/ParseUser.php +++ b/src/Parse/ParseUser.php @@ -51,7 +51,6 @@ public function getUsername() */ public function setUsername($username) { - $this->set('authData.anonymous', null); return $this->set('username', $username); } @@ -580,6 +579,15 @@ public function isCurrent() return false; } + /** + * Remove current user's anonymous AuthData + */ + private function clearAnonymousAuthData() + { + $json = json_encode(['authData' => [ 'anonymous' => null]]); + ParseClient::_request('PUT', 'classes/_User/' . $this->getObjectId(), null, $json, true); + } + /** * Save the current user object, unless it is not signed up. * @@ -590,7 +598,12 @@ public function isCurrent() public function save($useMasterKey = false) { if ($this->getObjectId()) { + $wasAnonymous = isset($this->operationSet['username']) + && $this->operationSet['username'] instanceof \Parse\Internal\SetOperation; parent::save($useMasterKey); + if ($wasAnonymous) { + $this->clearAnonymousAuthData(); + } } else { throw new ParseException( 'You must call signUp to create a new User.',