Last active
January 21, 2020 17:07
-
-
Save leifermendez/60fe5586bca7fc3348bdd85e19b14b83 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let KairosSDK = {}; | |
KairosSDK.login = () => { | |
const iframe = document.getElementById('iframe_kairos_app_sdk'); | |
iframe.contentWindow.postMessage({ | |
event: 'session' | |
}, '*'); | |
}; | |
KairosSDK.check = () => { | |
const token = window.localStorage.getItem('KairosSDK_TOKEN'); | |
const user = window.localStorage.getItem('KairosSDK_USER'); | |
return {token, user}; | |
}; | |
KairosSDK.receiveMessage = (opt) => { | |
if (opt.data.event === 'session_result') { | |
console.log(opt.data); | |
if (opt.data && opt.data.token) { | |
window.localStorage.setItem('KairosSDK_TOKEN', opt.data.token); | |
} | |
if (opt.data && opt.data.user) { | |
window.localStorage.setItem('KairosSDK_USER', opt.data.user); | |
} | |
return opt.data; | |
} else { | |
return false; | |
} | |
}; | |
if (window.addEventListener) { | |
window.addEventListener("message", KairosSDK.receiveMessage, false); | |
} else { | |
window.attachEvent("onmessage", KairosSDK.receiveMessage); | |
} | |
window.KairosSDK = KairosSDK; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Script que contiene funciones principales para poder acceder al localStorage del otro dominio donde se inserte el iframe