K.Kan
K.Kan

Reputation: 25

Parse REST api Logout 401 unauthorized

I am using the Parse REST API in my javascript app and struggling to get the logout function working.

I can login and signup users just fine but logging out throws an error 'POST https://api.parse.com/1/logout 401 (Unauthorized)'.

here is my code:

logout: function(user) {
  var config = {
    headers:{
        'X-Parse-Application-Id': PARSE_CREDENTIALS.APP_ID,
        'X-Parse-REST-API-Key':PARSE_CREDENTIALS.REST_API_KEY,
        'X-Parse-Session-Token': user.sessionToken
    }
  };
  return $http.post('https://api.parse.com/1/logout', config);
}

I am successfully getting the current users sessionToken but it just doesn't seem to work.

Am I missing something here. Any help would be greatly appreciated.

Upvotes: 1

Views: 1737

Answers (1)

Seb
Seb

Reputation: 1113

Actually I just found the answer here: Parse Logout 401 unauthorized using REST api

Just adding and empty data attribute worked for me as well! This is the code:

// define an empty object as required by $http
var mydata = {};
return $http.post(EXPRESSAPP.X_REST_API + 'logout', mydata, {
    headers:{
        'X-Parse-Application-Id': PARSE_CREDENTIALS.APP_ID,
        'X-Parse-REST-API-Key': PARSE_CREDENTIALS.APP_ID,
        'X-Parse-Session-Token': data.sessionToken
        }
});

Upvotes: 1

Related Questions