Refactored to use switch with fall through for readability
This commit is contained in:
parent
d3a2617d3c
commit
b92494f023
1 changed files with 17 additions and 16 deletions
|
@ -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() {
|
||||
|
|
Loading…
Reference in a new issue