simplified unpairing

This commit is contained in:
Josh Harvey 2014-04-20 12:07:48 +03:00
parent e50567ff81
commit 6ed979b1af
3 changed files with 14 additions and 44 deletions

View file

@ -89,13 +89,18 @@ module.exports = function (options) {
if (options.https) {
authMiddleware = function(req, res, next) {
var fingerprint = req.connection.getPeerCertificate().fingerprint;
var e = new Error('Unauthorized');
e.status = 401;
config.isAuthorized(fingerprint, function (err, device) {
if (err) { return next(e); }
if (!device) { return next(e); }
req.device = device;
if (err) {
var serverError = new Error('Internal Server Error');
serverError.status = 500;
return next(serverError);
}
if (!device) {
var pairError = new Error('Not Found');
pairError.status = 404;
return next(pairError);
}
next();
});
};