0

In Parse PHP SDK If the current user want to change his Email/username normally Parse check if username used by other user and if it is used it will return error, now this is good and work perfectly so far but the issue is the session is automatically updates to the new value where it failed.

so basically the session for the current user updated even if it wasn't for the backend

Steps to reproduce

$currentUser = Parse\ParseUser::getCurrentUser();
echo "Current Username is : ". $currentUser->get("username");

if ($currentUser) {
  $currentUser->set("username", "ww");
try {
        $currentUser->save();
        echo "UPDATED";
    } catch (Parse\ParseException $er) {
        $ex = $er->getMessage();
        echo "<br> Error: ". $ex;
    }
}

here is a video that explains more:

https://youtu.be/KWS9fW5MReA

3
  • Since you have updated the object your PHP application, it will keep updated locally unless you reset the action. So you can either save the old username and reverse the action in your catch method or $currentUser->fetch() in your catch method, or instantiate a new user object, do the change attempt in this new object, and finally $currentUser->fetch() only in case of success. Commented Aug 2, 2019 at 16:36
  • @DaviMacêdo worked perfect after i did $currentUser->fetch() can you post your comment in answer so i can mark it as accepted answer, thank you ! Commented Aug 3, 2019 at 3:03
  • 1
    Glad to know! Just posted the answer. Commented Aug 3, 2019 at 17:25

1 Answer 1

1

Since you have updated the object in your PHP application, it will keep updated locally unless you reset the action. So you can either:

  • save the old username and reverse the action in your catch method; or
  • use $currentUser->fetch() in your catch method; or
  • instantiate a new user object, do the change attempt in this new object, and finally $currentUser->fetch() only in case of success.

See below one of the possible solutions:

$currentUser = Parse\ParseUser::getCurrentUser();
echo "Current Username is : ". $currentUser->get("username");

if ($currentUser) {
  $currentUser->set("username", "ww");
try {
        $currentUser->save();
        echo "UPDATED";
    } catch (Parse\ParseException $er) {
        $currentUser->fetch();
        $ex = $er->getMessage();
        echo "<br> Error: ". $ex;
    }
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.