1

i need to delete a user form parse sdk with javascript, i tried loading the user query and then calling the destroy() but it gives me:

[HTTP/1.1 400 Bad Request]

my code is here

var query = new Parse.Query("User");
query.equalTo("email", '[email protected]');
query.find().then(function(results) {
console.log(results[0]);
results[0].destroy();
});

this won't destroy the user. can anybody help?

2
  • Use the console to see what request is sent to the Parse server. It has to be a DELETE request (not GET nor POST), and has to contain the X-Parse-Session-Token. Docs: parse.com/docs/rest#users-deleting Commented Jan 4, 2015 at 16:14
  • the browser is sending POST request. i am using javascript, is there anyway to do it! Commented Jan 4, 2015 at 16:21

1 Answer 1

1

with the help of Bjorn's answer i figured out a way doing it. i had to use REST api of parse sdk and generate a DELETE request with a proper session key of the user.

var CurrentUser = Parse.User.current();
console.log(CurrentUser);

var sessiontoken;


Parse.User.logIn(CurrentUser.attributes.username, document.getElementById("curpassword").value, {
    success: function (user) {
        user.set("StayLoggedIn", "false");

        console.log(user._sessionToken);
        sessiontoken = user._sessionToken;
        user.save();



        $.ajax({
            url: 'https://api.parse.com/1/users/' + user.id,
            type: 'DELETE',
            headers: {'X-Parse-Application-Id': APP_ID, 'X-Parse-REST-API-Key': REST_KEY, 'X-Parse-Session-Token': sessiontoken},
            success: function (result) {
                // Do something with the result
                alert("you have successfully deleted your account.");
                Parse.User.logOut();
                window.location.href = "index.html";
            }
        });
        //  location.reload();
    },
    error: function (user, error) {
        //alert(error);
        alert("incorrect username or password");
    }
});
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.