Skip to content

Commit 7bb3eea

Browse files
authored
Merge pull request #35 from umbraco/bugfix/hubspot-auth-events
Fix succes event handled multiple times
2 parents 6e35f81 + 726a4c9 commit 7bb3eea

File tree

1 file changed

+10
-1
lines changed
  • src/Umbraco.Cms.Integrations.Crm.Hubspot/App_Plugins/UmbracoCms.Integrations/Crm/Hubspot/js

1 file changed

+10
-1
lines changed

src/Umbraco.Cms.Integrations.Crm.Hubspot/App_Plugins/UmbracoCms.Integrations/Crm/Hubspot/js/settings.controller.js

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@
44

55
const oauthName = "OAuth";
66

7-
vm.oauthSetup = {};
7+
vm.oauthSetup = {
8+
authEventHandled : false
9+
};
810
vm.status = {};
911

1012
$scope.$on('formSubmitting', function () {
@@ -49,6 +51,7 @@
4951
vm.onRevokeToken = function() {
5052
umbracoCmsIntegrationsCrmHubspotResource.revokeAccessToken().then(function (response) {
5153
vm.oauthSetup.isConnected = false;
54+
vm.oauthSetup.authEventHandled = false;
5255

5356
if(typeof $scope.connected === "undefined")
5457
notificationsService.success("HubSpot Configuration", "OAuth connection revoked.");
@@ -60,9 +63,15 @@
6063

6164
// authorization listener
6265
window.addEventListener("message", function (event) {
66+
6367
if (event.data.type === "hubspot:oauth:success") {
6468

69+
if (vm.oauthSetup.authEventHandled === true) return;
70+
6571
umbracoCmsIntegrationsCrmHubspotResource.getAccessToken(event.data.code).then(function (response) {
72+
73+
vm.oauthSetup.authEventHandled = true;
74+
6675
if (response.startsWith("Error:")) {
6776
if (typeof $scope.connected === "undefined")
6877
notificationsService.error("HubSpot Configuration", response);

0 commit comments

Comments
 (0)