From b92494f0238da91b95b3e4cc98de8fe4fe30cef2 Mon Sep 17 00:00:00 2001 From: Jeroen Rosenberg Date: Fri, 16 May 2014 13:52:59 +0200 Subject: [PATCH] Refactored to use switch with fall through for readability --- integration/js/src/main/resources/keycloak.js | 33 ++++++++++--------- 1 file changed, 17 insertions(+), 16 deletions(-) diff --git a/integration/js/src/main/resources/keycloak.js b/integration/js/src/main/resources/keycloak.js index 188c99d357..6dc108fc63 100755 --- a/integration/js/src/main/resources/keycloak.js +++ b/integration/js/src/main/resources/keycloak.js @@ -54,21 +54,22 @@ var Keycloak = function (config) { if (initOptions.token || initOptions.refreshToken) { setToken(initOptions.token, initOptions.refreshToken); } else if (initOptions.onLoad) { - if (initOptions.onLoad == 'check-sso' || initOptions.onLoad == 'login-required') { - var options = {}; - if (initOptions.onLoad == 'check-sso') { + var options = {}; + switch (initOptions.onLoad) { + case 'check-sso': options.prompt = 'none'; - } - var p = kc.login(options); - if (p) { - p.success(function() { - initPromise.setSuccess(); - }).error(function() { - initPromise.setError(); - }); - }; - } else { - throw 'Invalid value for onLoad'; + case 'login-required': + var p = kc.login(options); + if (p) { + p.success(function() { + initPromise.setSuccess(); + }).error(function() { + initPromise.setError(); + }); + }; + break; + default: + throw 'Invalid value for onLoad'; } } } else { @@ -143,7 +144,7 @@ var Keycloak = function (config) { kc.hasRealmRole = function (role) { var access = kc.realmAccess; - return access && access.roles.indexOf(role) >= 0 || false; + return !!access && access.roles.indexOf(role) >= 0; } kc.hasResourceRole = function(role, resource) { @@ -152,7 +153,7 @@ var Keycloak = function (config) { } var access = kc.resourceAccess[resource || kc.clientId]; - return access && access.roles.indexOf(role) >= 0 || false; + return !!access && access.roles.indexOf(role) >= 0; } kc.loadUserProfile = function() {