From ab49b30df4b8f45ddf6f1a413a8c1d5d4bc38067 Mon Sep 17 00:00:00 2001 From: Saltuk Alakus Date: Sun, 9 Jul 2017 16:15:08 +0300 Subject: [PATCH] handle undefined user and bump version to 1.2 --- build/bundle.js | 18 ++++++++++-------- index.js | 18 ++++++++++-------- package.json | 2 +- webtask.json | 2 +- 4 files changed, 22 insertions(+), 18 deletions(-) diff --git a/build/bundle.js b/build/bundle.js index 8da2ebc..e686745 100644 --- a/build/bundle.js +++ b/build/bundle.js @@ -213,16 +213,18 @@ module.exports = console.log('Error getting user id', err); cb(null, err); } else { - // This should be a unique user because we filter + // This should be a unique single user because we filter // with connection and user name. So getting the first // item in the returned array. - if (body.length > 1) { - console.log("USER SHOULD BE UNIQUE!!!"); - console.log(body); + if (body.length !== 1) { + cb(null, "Multiple user or no user for the requested name! Log Ignored"); + } else if (typeof body[0].user_id === 'undefined' || !body[0].user_id) { + cb(null, "User Id missing! Log Ignored!"); + } else { + console.log("USER ID ======="); + console.log(body[0].user_id); + cb(body[0].user_id); } - console.log("USER ID ======="); - console.log(body[0].user_id); - cb(body[0].user_id); } }); } @@ -347,7 +349,7 @@ module.exports = module.exports = { "title": "Auth0 Unblock Users", "name": "auth0-unblock-users", - "version": "1.1.0", + "version": "1.2.0", "author": "saltuk", "description": "This extension will search for blocked users in the logs and unblock them", "type": "cron", diff --git a/index.js b/index.js index 7a299f3..dce3e17 100644 --- a/index.js +++ b/index.js @@ -173,16 +173,18 @@ function getUserId(domain, token, connection, name, cb) { console.log('Error getting user id', err); cb(null, err); } else { - // This should be a unique user because we filter + // This should be a unique single user because we filter // with connection and user name. So getting the first // item in the returned array. - if (body.length > 1) { - console.log("USER SHOULD BE UNIQUE!!!"); - console.log(body); - } - console.log("USER ID ======="); - console.log(body[0].user_id); - cb(body[0].user_id); + if (body.length !== 1) { + cb(null, "Multiple user or no user for the requested name! Log Ignored"); + } else if (typeof body[0].user_id === 'undefined' || !body[0].user_id){ + cb(null, "User Id missing! Log Ignored!"); + } else { + console.log("USER ID ======="); + console.log(body[0].user_id); + cb(body[0].user_id); + } } }); } diff --git a/package.json b/package.json index b0a3e9c..f484774 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "auth0-unblock-users", - "version": "1.1.0", + "version": "1.2.0", "description": "This extension will search for blocked users in the logs and unblock them", "main": "index.js", "scripts": { diff --git a/webtask.json b/webtask.json index 4b6fb99..f9abcb6 100644 --- a/webtask.json +++ b/webtask.json @@ -1,7 +1,7 @@ { "title": "Auth0 Unblock Users", "name": "auth0-unblock-users", - "version": "1.1.0", + "version": "1.2.0", "author": "saltuk", "description": "This extension will search for blocked users in the logs and unblock them", "type": "cron",