From d9a4c1c96db19a9b0a338ed9b47f470bb4e2a3e4 Mon Sep 17 00:00:00 2001 From: Siggi Simonarson Date: Tue, 10 Oct 2023 12:31:07 -0700 Subject: [PATCH] Filter out any messages that aren't from buildbuddy --- app/auth/auth_service.ts | 2 +- app/errors/error_service.ts | 5 ++++- app/util/popup.ts | 7 +++++-- 3 files changed, 10 insertions(+), 4 deletions(-) diff --git a/app/auth/auth_service.ts b/app/auth/auth_service.ts index ea897cbbe7e..8512e3b484a 100644 --- a/app/auth/auth_service.ts +++ b/app/auth/auth_service.ts @@ -104,7 +104,7 @@ export class AuthService { } handleLoggedIn(response: user.GetUserResponse) { - window.opener?.postMessage("", window.location.origin); + window.opener?.postMessage({ type: "buildbuddy_message", error: "", success: true }, window.location.origin); localStorage.removeItem(AUTO_LOGIN_ATTEMPTED_STORAGE_KEY); this.emitUser(this.userFromResponse(response)); } diff --git a/app/errors/error_service.ts b/app/errors/error_service.ts index 889b7c43578..d5de81e4a5c 100644 --- a/app/errors/error_service.ts +++ b/app/errors/error_service.ts @@ -21,7 +21,10 @@ export class ErrorService { return; } alertService.error(String(error)); - window.opener?.postMessage(String(error), window.location.origin); + window.opener?.postMessage( + { type: "buildbuddy_message", error: String(error), success: false }, + window.location.origin + ); } } diff --git a/app/util/popup.ts b/app/util/popup.ts index 3a17e2c316f..a7ac570635f 100644 --- a/app/util/popup.ts +++ b/app/util/popup.ts @@ -33,13 +33,16 @@ export default { // If we receieve a message, resolve or reject the promise based on the presence of error text. popupEventListener = function (e: MessageEvent) { + if (!e.data || e.data.type != "buildbuddy_message") { + return; + } clearTimeout(timeoutId); clearInterval(popupTimer); window.removeEventListener("message", popupEventListener, false); popup?.close(); console.log("Received message from popup: " + e.data); - if (e.data != "") { - reject(e.data); + if (!e.data.success) { + reject(e.data.error); } resolve(e.data); };