From bd75194526e18c68785d7b4934fa2a93e4d27f72 Mon Sep 17 00:00:00 2001 From: Rafael Taranto Date: Thu, 1 Nov 2018 18:07:47 -0300 Subject: [PATCH] Fix exception on clock skew (#202) * Fix exception on clock skew * Return device name instead of db object --- lib/pairing.js | 9 +-------- lib/routes.js | 6 +++--- 2 files changed, 4 insertions(+), 11 deletions(-) diff --git a/lib/pairing.js b/lib/pairing.js index bc2d4ccc..6fc8599d 100644 --- a/lib/pairing.js +++ b/lib/pairing.js @@ -74,14 +74,7 @@ function isPaired (deviceId) { const sql = 'select device_id, name from devices where device_id=$1 and paired=TRUE' return db.oneOrNone(sql, [deviceId]) - .then(row => { - const deviceName = row.name - const isDevicePaired = row && row.device_id === deviceId - return { - deviceName: deviceName, - isDevicePaired: isDevicePaired - } - }) + .then(row => row && row.device_id === deviceId ? row.name : false) } module.exports = {pair, unpair, authorizeCaDownload, isPaired} diff --git a/lib/routes.js b/lib/routes.js index 10c7af87..8deafe3f 100644 --- a/lib/routes.js +++ b/lib/routes.js @@ -311,10 +311,10 @@ function authorize (req, res, next) { const deviceId = req.deviceId return pairing.isPaired(deviceId) - .then(r => { - if (r.isDevicePaired) { + .then(deviceName => { + if (deviceName) { req.deviceId = deviceId - req.deviceName = r.deviceName + req.deviceName = deviceName return next() }