Non-authenticated POSTing to /User/logout produces an error 500
The User.logout code appears to do this intentionally. It feels like the wrong error response code, but I don't know what the correct code is. Here is the User.logout code, for reference,
User.logout = function(tokenId, fn) {
this.relations.accessTokens.modelTo.findById(tokenId, function(err, accessToken) {
if (err) {
fn(err);
} else if (accessToken) {
accessToken.destroy(fn);
} else {
fn(new Error('could not find accessToken'));
}
});
};
Please advise if that is the intended functionality or not.
Maybe 400 is better. Do you want to submit a patch?
- User.logout requires logged-in user. And as any other protected method it has to return 401.
Perhaps the problem here is just that the ACL is wrong?
{
"principalType": "ROLE",
"principalId": "$everyone",
"permission": "ALLOW",
"property": "logout"
},
principalId has to be $authenticated
@raymondfeng can you confirm that the ACL is off? If so, I'm happy to put together a patch.
@raymondfeng Assigning to you since you are already working on this.
A missing or invalid access token should return a 401 per HTTP 1.1 RFC. See my response to related issue: https://github.com/strongloop/loopback/issues/1496
I'm also having the 500 error. I'm essentially using the same AuthService and controllers that came with the loopback-getting-started-intermediate.
The only difference is the following, any ideas? Thanks in advance.
$scope.login = function(e) {
console.log('logging...');
AuthService.login($scope.email, $scope.password)
.then(function() {
console.log('I am inside!');
window.history.back();
//$state.go('add-review');
},
function(err, token)
{
console.log(err);
$scope.loginMsg = err.data.error.message;
});
};
}])
.controller('AuthLogoutController', ['$scope', 'AuthService', 'Helper',
function($scope, AuthService, Helper) {
AuthService.logout()
.then(function() {
//$state.go('all-reviews');
});
}])
@doublemarked Original bug in this issue is fixed by PR https://github.com/strongloop/loopback/pull/1496 Will be closing this issue