Skip to content

Instantly share code, notes, and snippets.

@leifermendez
Last active January 21, 2020 17:07
Show Gist options
  • Save leifermendez/60fe5586bca7fc3348bdd85e19b14b83 to your computer and use it in GitHub Desktop.
Save leifermendez/60fe5586bca7fc3348bdd85e19b14b83 to your computer and use it in GitHub Desktop.
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;
@leifermendez
Copy link
Author

Script que contiene funciones principales para poder acceder al localStorage del otro dominio donde se inserte el iframe

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment