0

We started the app with Parse and have been hitting problems since it shut down.

Destroying a user is not working in this deleteUser function

Parse.Cloud.define('deleteUser', function(request, response) {
var objectId = request.params.objectId;

if(!objectId || objectId.length === 0 || !objectId.trim()) {
    response.error("The user object id is needed to perform this action.");
}

Parse.Cloud.useMasterKey();
var query = new Parse.Query(Parse.User);
query.get(objectId, {
  success: function(user) {
    user.destroy(null, {
      success: response.success(user),
      error: function(user, error) {
        response.error(error);
      }
    });
  },
  error: function(error) {
    response.error("Could not find the user.");
  }
});
});

deleteEvent works just fine and I've also tried copying this exact syntax for deleteUser with no luck.

Parse.Cloud.define('deleteEvent', function(request, response) {

var objectId = request.params.objectId;

if(!objectId || objectId.length === 0 || !objectId.trim()) {
    response.error('The event object id is needed to perform this action.');
    return;
}

Parse.Cloud.useMasterKey();
var query = new Parse.Query(Parse.Object.extend('Events'));
query.get(objectId, {
    success: function(event) {
        event.destroy();
        response.success('Successfully deleted event.');
    },
    error: function(error) {
        response.error('Could not find the event.');
    }
});
});

The function finishes with the success call in the logs, but user.destroy() never actually deletes the user.

I console.log all of the params, IDs, and arguments to make sure I'm getting the expected. Is there a special way to delete Parse users?

This suddenly stopped working last week.

I've tried on Parse v1.6.14 and v1.9.2

Thanks in advance for the help!

2 Answers 2

1

As someone said, Parse.Cloud.useMasterKey() is deprecated in parse-server. You now need to specify useMasterKey flag, or pass a sessionToken (to impersonate User) to methods accessing DB (get, save, first, count,...). So, change your code accordingly:

Parse.Cloud.define('deleteUser', function(request, response) {
var objectId = request.params.objectId;

if(!objectId || objectId.length === 0 || !objectId.trim()) {
    response.error("The user object id is needed to perform this action.");
}

var query = new Parse.Query(Parse.User);
query.get(objectId, {
  useMasterKey: true, //HERE (1/2)
  success: function(user) {
    user.destroy({
      useMasterKey: true, //HERE (2/2)
      success: response.success(user),
      error: function(user, error) {
        response.error(error);
      }
    });
  },
  error: function(error) {
    response.error("Could not find the user.");
  }
});
});
Sign up to request clarification or add additional context in comments.

1 Comment

I see, sweet and simple reason. Thank you Cipi and Cliffordwh for your help!
1

This is because Parse.Cloud.useMasterKey() is deprecated since Parse-server version 2.3.0. You now need to make use of useMasterKey: true when using the users table.

   var query = new Parse.Query(Parse.User);
       query.get({ useMasterKey: true }).then(.......)

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.