Skip to content

Commit

Permalink
add cookies
Browse files Browse the repository at this point in the history
  • Loading branch information
Lily Kuang committed Dec 2, 2021
1 parent cb0897d commit 550099f
Showing 1 changed file with 5 additions and 12 deletions.
17 changes: 5 additions & 12 deletions superset-frontend/src/embedded/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,35 +23,28 @@ import App from 'src/views/App';
const MESSAGE_TYPE = '__embedded_comms__';
const ALLOW_ORIGINS = ['http://127.0.0.1:9001', 'http://localhost:9001'];

console.log('ADD THE LISTENER');
function start(token: string) {
document.cookie = `__guest_token__=${token}`;
ReactDOM.render(<App />, document.getElementById('app'));
}

window.addEventListener('message', function (event) {
if (!ALLOW_ORIGINS.includes(event.origin)) {
console.log(
'embedded page received message from unauthorized origin',
event,
);
return;
}

let data: any = {};
try {
data = JSON.parse(event.data);
} catch (err) {
console.error('embedded page received non-json message', event);
return;
}

if (data.type !== MESSAGE_TYPE) {
console.log('embedded page ignoring non-embedded-comms message', event);
return;
}

console.log('embedded page received message', event);
if (data.embedToken) {
start(data.embedToken);
}
});

function start(token: string) {
ReactDOM.render(<App />, document.getElementById('app'));
}

0 comments on commit 550099f

Please sign in to comment.