Skip to content

Commit

Permalink
fix for feature flag off case
Browse files Browse the repository at this point in the history
  • Loading branch information
Gaurav0 committed Sep 17, 2024
1 parent 03437d6 commit 35563b2
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 23 deletions.
36 changes: 17 additions & 19 deletions addon/mixins/ui-service-mixin.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,25 +60,23 @@ var ServicesMixin = Mixin.create({
// Using postMessage as an alternative to localStorage/storageEvent
// for case of web site embedded in iframe
messageToriiEventHandler = function (messageEvent) {
if (messageEvent.source === service.remote) {
if (messageEvent.data === 'getPendingRequestKey') {
service.remote.postMessage(
JSON.stringify({ pendingRequestKey: service.pendingRequestKey }),
window.location.origin
);
} else {
const msg = JSON.parse(messageEvent.data);
const key = Object.keys(msg)[0];
var remoteIdFromEvent = PopupIdSerializer.deserialize(
decodeURIComponent(key)
);
if (remoteId === remoteIdFromEvent) {
var data = parseMessage(msg[key], keys);
localStorage.removeItem(key);
run(function () {
resolve(data);
});
}
if (messageEvent.data === 'getPendingRequestKey') {
messageEvent.source.postMessage(
JSON.stringify({ pendingRequestKey: service.pendingRequestKey }),
window.location.origin
);
} else {
const msg = JSON.parse(messageEvent.data);
const key = Object.keys(msg)[0];
var remoteIdFromEvent = PopupIdSerializer.deserialize(
decodeURIComponent(key)
);
if (remoteId === remoteIdFromEvent) {
var data = parseMessage(msg[key], keys);
localStorage.removeItem(key);
run(function () {
resolve(data);
});
}
}
};
Expand Down
14 changes: 10 additions & 4 deletions public/redirect.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,31 +7,37 @@
const CURRENT_REQUEST_KEY = '__torii_request';
let pendingRequestKey = window.localStorage.getItem(CURRENT_REQUEST_KEY);
const origin = window.location.origin;
let opener = window.opener;
try {
if (opener && opener.parent && opener.parent.origin === origin) {
opener = opener.parent;
}
} catch {}

if (pendingRequestKey) {
window.localStorage.removeItem(CURRENT_REQUEST_KEY);
const url = window.location.toString();
window.localStorage.setItem(pendingRequestKey, url);
const obj = {};
obj[pendingRequestKey] = url;
window.opener?.postMessage(
opener?.postMessage(
JSON.stringify(obj),
origin
);

window.close();
} else {
// localStorage not shared with opener due to browser restrictions
window.opener.postMessage('getPendingRequestKey', origin);
opener?.postMessage('getPendingRequestKey', origin);
window.addEventListener('message', function(messageEvent) {
if (messageEvent.source === window.opener) {
if (messageEvent.source === opener) {
const msg = JSON.parse(messageEvent.data);
if (msg.pendingRequestKey) {
pendingRequestKey = msg.pendingRequestKey;
url = window.location.toString();
const obj = {};
obj[pendingRequestKey] = url;
window.opener.postMessage(
opener.postMessage(
JSON.stringify(obj),
origin
);
Expand Down

0 comments on commit 35563b2

Please sign in to comment.