-
Notifications
You must be signed in to change notification settings - Fork 6
Open
Description
In some situations it would be very useful to have a custom payload returned when authentication fails. However, it seems that this isn't possible to achieve.
The obvious way of doing this based on the current documentation would be something like:
percolator.route('/api/authentication/internal', {
basicAuthenticate: function (username, password, req, res, cb) {
if (username === 'username' && password === 'password') {
cb(null, {username: username, password: password});
} else {
res.object({'hello': 'world'}).send();
cb(true);
}
},
POST : function (req, res) {
res.object({auth: req.authenticated}).send();
}
});However, if the basicAuthenticate function does a res.object().send() then you get an "Error: Can't set headers after they are sent" logged, and whilst the custom object is sent, the HTTP Status code is still set to 200. If the basicAuthenticate does a res.object() but doesn't do a send() then the custom object is never sent.
Metadata
Metadata
Assignees
Labels
No labels