flex-plugin
Advanced tools
Comparing version 0.4.0 to 0.5.0
@@ -0,1 +1,4 @@ | ||
const REDIRECT_KEY = 'LOCAL_FLEX_PLUGIN_LOGIN_REDIRECT'; | ||
const FIRST_LOAD_KEY = 'LOCAL_FLEX_PLUGIN_FIRST_LOAD'; | ||
function loadFlex() { | ||
@@ -11,8 +14,23 @@ if ( | ||
} else { | ||
Twilio.Flex.create(appConfig).then(flex => { | ||
flex.init('#container'); | ||
}).catch(err => { | ||
window.location.replace('http://www.twilio.com/service-login/flex?localPort=8080'); | ||
}); | ||
const loginUrl = `http://www.twilio.com/service-login/flex/${appConfig.sso.accountSid || accountSid}?localPort=${window.location.port}` | ||
if (!localStorage.getItem(FIRST_LOAD_KEY)) { | ||
localStorage.setItem(FIRST_LOAD_KEY, 'redirected'); | ||
window.location.replace(loginUrl); | ||
return; | ||
} else { | ||
Twilio.Flex.create(appConfig).then(flex => { | ||
localStorage.removeItem(REDIRECT_KEY); | ||
localStorage.removeItem(FIRST_LOAD_KEY); | ||
flex.init('#container'); | ||
}).catch(err => { | ||
if (!localStorage.getItem(REDIRECT_KEY)) { | ||
localStorage.setItem(REDIRECT_KEY, 'redirected'); | ||
window.location.replace(loginUrl); | ||
} else { | ||
throw new Error('Failed to authenticate user.'); | ||
} | ||
}); | ||
} | ||
} | ||
} |
@@ -5,2 +5,5 @@ import * as Flex from '@twilio/flex-ui'; | ||
serviceBaseUrl?: string; | ||
appConfig?: { | ||
serviceBaseUrl?: string; | ||
}; | ||
} | ||
@@ -7,0 +10,0 @@ } |
@@ -27,2 +27,5 @@ "use strict"; | ||
} | ||
if (window.appConfig && window.appConfig.serviceBaseUrl) { | ||
return window.appConfig.serviceBaseUrl; | ||
} | ||
if (document && document.currentScript) { | ||
@@ -29,0 +32,0 @@ var pluginScript = document.currentScript; |
{ | ||
"name": "flex-plugin", | ||
"version": "0.4.0", | ||
"version": "0.5.0", | ||
"bin": { | ||
@@ -37,3 +37,3 @@ "flex-check-start": "./bin/check-start" | ||
}, | ||
"gitHead": "fb838f4eade771c991f4422a3a27586c16c9c82b", | ||
"gitHead": "d76062a30f625e908e4d83ff34fff5240084407b", | ||
"dependencies": { | ||
@@ -40,0 +40,0 @@ "chalk": "^2.4.1", |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
9532
105