remote_billing: Fix /self-hosted-billing/ handling for desktop app.

When you click "Plan management", the desktop app opens
/self-hosted-billing/ in your browser immediately. So that works badly
if you're already logged into another account in the browser, since that
session will be used and it may be for a different user account than in
the desktop app, causing unintended behavior.

The solution is to replace the on click behavior for "Plan management"
in the desktop app case, to instead make a request to a new endpoint
/json/self-hosted-billing, which provides the billing access url in a
json response. The desktop app takes that URL and window.open()s it (in
the browser). And so a remote billing session for the intended user will
be obtained.
This commit is contained in:
Mateusz Mandera
2024-01-06 20:31:41 +01:00
committed by Tim Abbott
parent dcec36b824
commit fc247cba3f
6 changed files with 154 additions and 23 deletions

View File

@@ -2,6 +2,8 @@ import $ from "jquery";
import * as browser_history from "./browser_history";
import * as channel from "./channel";
import * as feedback_widget from "./feedback_widget";
import {$t} from "./i18n";
import * as message_store from "./message_store";
import * as narrow from "./narrow";
import * as stream_data from "./stream_data";
@@ -63,3 +65,32 @@ if (window.electron_bridge !== undefined) {
});
});
}
export function initialize() {
if (window.electron_bridge === undefined) {
return;
}
$(document).on("click", "#open-self-hosted-billing", (event) => {
event.preventDefault();
const url = "/json/self-hosted-billing";
channel.get({
url,
success(data) {
window.open(data.billing_access_url, "_blank", "noopener,noreferrer");
},
error(xhr) {
if (xhr.responseJSON?.msg) {
feedback_widget.show({
populate($container) {
$container.text(xhr.responseJSON.msg);
},
title_text: $t({defaultMessage: "Error"}),
});
}
},
});
});
}