Skip to content

Commit

Permalink
Filter out any messages that aren't from buildbuddy
Browse files Browse the repository at this point in the history
  • Loading branch information
siggisim committed Oct 10, 2023
1 parent 95e498a commit d9a4c1c
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 4 deletions.
2 changes: 1 addition & 1 deletion app/auth/auth_service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}
Expand Down
5 changes: 4 additions & 1 deletion app/errors/error_service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
);
}
}

Expand Down
7 changes: 5 additions & 2 deletions app/util/popup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
};
Expand Down

0 comments on commit d9a4c1c

Please sign in to comment.