diff --git a/lib/authService/authenticate.js b/lib/authService/authenticate.js index 58e39d37..f40f74d8 100644 --- a/lib/authService/authenticate.js +++ b/lib/authService/authenticate.js @@ -99,7 +99,7 @@ class Authenticate { // check whether accounts contains only one element and role is device var accounts = decoded_token.accounts; var did = decoded_token.device_id ? decoded_token.device_id : decoded_token.sub; - var accountId = accounts ? accounts[0].id : null; + var accountId = accounts && accounts.length > 0 ? accounts[0].id : null; let realm = getRealm(decoded_token); // put realm/device into the list of accepted topics await this.cache.setValue(realm + "/" + did, "acl", true);