Skip to content

Commit 01de28d

Browse files
acinaderdplewis
authored andcommitted
alternate method to remove auth data (#429)
* alternate method to remove auth data which has the added benefit of working with current versions of mongo * listen to lint! * lint take 2.
1 parent 97d9455 commit 01de28d

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed

src/Parse/ParseUser.php

+14-1
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,6 @@ public function getUsername()
5151
*/
5252
public function setUsername($username)
5353
{
54-
$this->set('authData.anonymous', null);
5554
return $this->set('username', $username);
5655
}
5756

@@ -580,6 +579,15 @@ public function isCurrent()
580579
return false;
581580
}
582581

582+
/**
583+
* Remove current user's anonymous AuthData
584+
*/
585+
private function clearAnonymousAuthData()
586+
{
587+
$json = json_encode(['authData' => [ 'anonymous' => null]]);
588+
ParseClient::_request('PUT', 'classes/_User/' . $this->getObjectId(), null, $json, true);
589+
}
590+
583591
/**
584592
* Save the current user object, unless it is not signed up.
585593
*
@@ -590,7 +598,12 @@ public function isCurrent()
590598
public function save($useMasterKey = false)
591599
{
592600
if ($this->getObjectId()) {
601+
$wasAnonymous = isset($this->operationSet['username'])
602+
&& $this->operationSet['username'] instanceof \Parse\Internal\SetOperation;
593603
parent::save($useMasterKey);
604+
if ($wasAnonymous) {
605+
$this->clearAnonymousAuthData();
606+
}
594607
} else {
595608
throw new ParseException(
596609
'You must call signUp to create a new User.',

0 commit comments

Comments
 (0)