@salesforcedevs/dx-components 0.59.0-avatar-button-11 → 0.59.0-avatar-button-12

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@salesforcedevs/dx-components",
3
- "version": "0.59.0-avatar-button-11",
3
+ "version": "0.59.0-avatar-button-12",
4
4
  "description": "DX Lightning web components",
5
5
  "license": "MIT",
6
6
  "engines": {
@@ -14,6 +14,8 @@ declare global {
14
14
  SFIDWidget?: {
15
15
  logout(): void;
16
16
  login(): void;
17
+ openid_response: any;
18
+ disabled: boolean;
17
19
  };
18
20
  }
19
21
  }
@@ -53,13 +55,35 @@ export default class AvatarButton extends LightningElement {
53
55
  }
54
56
 
55
57
  connectedCallback() {
58
+ if (
59
+ new URLSearchParams(window.location.search).get("loginSuccess") ===
60
+ "true"
61
+ ) {
62
+ this.isLoading = true;
63
+ }
64
+
56
65
  window.addEventListener("tbid-login", this.handleSsoLogin);
57
66
  window.addEventListener("tbid-logout", this.handleSsoLogout);
58
67
 
59
- // Whenever this component is added to the DOM and there is not an SFIDWidget present, immediately request
60
- // user info; if the user is logged in and we receive the info, this component will display the avatar UI;
61
- // otherwise, it will display the login button.
62
- if (!window.SFIDWidget) {
68
+ const isWidgetDisabled = window.SFIDWidget?.disabled;
69
+ const isWidgetLoggedIn = window.SFIDWidget?.openid_response;
70
+
71
+ // If the component loads and (1) we are logging in and (2) the embedded login widget script
72
+ // is in the DOM but (3) the widget has either not loaded or not completed login yet, we
73
+ // defer the userInfo request in order to allow the SFIDWidget the time to trigger it (via
74
+ // it's own login handler) after SSO login. If any of (1) - (3) are false, then we request
75
+ // user info immediately. The check prevents duplicate requests.
76
+ if (
77
+ this.isLoading &&
78
+ (!window.SFIDWidget || (!isWidgetDisabled && !isWidgetLoggedIn)) &&
79
+ document.querySelector('script[src*="authProviderEmbeddedLogin"]')
80
+ ) {
81
+ setTimeout(() => {
82
+ if (!window.SFIDWidget?.openid_response) {
83
+ this.requestUserInfo();
84
+ }
85
+ }, 1000);
86
+ } else {
63
87
  this.requestUserInfo();
64
88
  }
65
89
  }
@@ -112,17 +136,16 @@ export default class AvatarButton extends LightningElement {
112
136
  token
113
137
  })
114
138
  });
139
+
140
+ // Unfortunately, the user info provided by the SFIDWidget on SSO login does not contain
141
+ // image URLs, so we also have to request it manually again
142
+ this.requestUserInfo();
115
143
  } catch (ex) {
116
144
  // If the request fails for some reason, fall back to whatever we've got
117
145
  this.updateAvatarWithUserInfo(this.userInfo);
118
146
  console.error(ex);
119
- return;
120
147
  }
121
148
  }
122
-
123
- // Unfortunately, the user info provided by the SFIDWidget on SSO login does not contain
124
- // image URLs, so we also have to request it manually again
125
- this.requestUserInfo();
126
149
  };
127
150
 
128
151
  private handleComponentLogin = () => {