Refactored to use switch with fall through for readability

This commit is contained in:
Jeroen Rosenberg 2014-05-16 13:52:59 +02:00
parent d3a2617d3c
commit b92494f023

View file

@ -54,11 +54,11 @@ 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') {
switch (initOptions.onLoad) {
case 'check-sso':
options.prompt = 'none';
}
case 'login-required':
var p = kc.login(options);
if (p) {
p.success(function() {
@ -67,7 +67,8 @@ var Keycloak = function (config) {
initPromise.setError();
});
};
} else {
break;
default:
throw 'Invalid value for onLoad';
}
}
@ -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() {