Search code examples
javascriptparse-platformparse-cloud-codeparse-server

Updating user in Cloud Code isn't reflecting locally


I am updating a field in my user object from cloud code such as

Parse.Cloud.define("update", function(req, res){
    req.user.unset("var");
    req.user.save(null, {
        useMasterKey: true,
    }).then(function(user){
        res.success("Updated");
    });
});

The problem is that while the updated value is reflected on the backend in the user table, the Parse.User.current() still references the value before update. I have tried calling

Parse.User.current().fetch()

but to no avail. I don't quite understand why this is happening because I can do this with other objects and it'll work as intended. Logging out and back in again does solve the problem but this is not convenient and won't be user friendly. Unsetting the value seems to keep the local user variable from "fetching" however setting the value to an empty string seems to make it work, but I don't believe this is a good practice and can cause unexpected results.


Solution

  • Calling fetch locally works for me but calling in cloud does not.