Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Filter out any window messages that aren't from buildbuddy #4989

Merged
merged 1 commit into from
Oct 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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