@salesforcedevs/dx-components 0.59.0-avatar-button-6 → 0.59.0-avatar-button-7

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-6",
3
+ "version": "0.59.0-avatar-button-7",
4
4
  "description": "DX Lightning web components",
5
5
  "license": "MIT",
6
6
  "engines": {
@@ -91,23 +91,31 @@ export default class AvatarButton extends LightningElement {
91
91
  private handleComponentLogout = this.handleLogout.bind(this, false);
92
92
 
93
93
  // This will only be called for "seamless SSO" login by the embedded login widget (SFIDWidget) on the website, if it exists.
94
- private handleSsoLogin = (event: Event) => {
95
- const userInfo = (event as CustomEvent).detail;
96
- if (userInfo) {
97
- this.updateAvatarWithUserInfo(userInfo);
98
- this._didReceiveUserInfo = true;
99
- // userInfo.access_token should always exist if an SSO login occurs, but we just check
100
- // for extra safety:
101
- if (userInfo.access_token) {
102
- // If an SSO login occurred and we have an SSO access token, we want to start using
103
- // it rather than some other non-linked access token, for the "seamless SSO"
104
- // experience.
105
- fetch(TBID_API_TOKEN_URL, {
94
+ private handleSsoLogin = async (event: Event) => {
95
+ const token = (event as CustomEvent).detail.userInfo?.access_token;
96
+
97
+ // `token` should always be defined if an SSO login occurs, but we check for extra safety
98
+ if (token) {
99
+ this.isLoading = true;
100
+ // If an SSO login occurred and we have an SSO access token, we want to start using
101
+ // it rather than some other non-linked access token, for the "seamless SSO"
102
+ // experience
103
+ try {
104
+ await fetch(TBID_API_TOKEN_URL, {
106
105
  method: "POST",
107
- body: userInfo.access_token
106
+ body: token
108
107
  });
108
+ } catch (ex) {
109
+ // If the request fails for some reason, fall back to whatever we've got
110
+ this.updateAvatarWithUserInfo(this.userInfo);
111
+ console.error(ex);
112
+ return;
109
113
  }
110
114
  }
115
+
116
+ // Unfortunately, the user info provided by the SFIDWidget on SSO login does not contain
117
+ // image URLs, so we also have to request it manually again
118
+ this.requestUserInfo();
111
119
  };
112
120
 
113
121
  private handleComponentLogin = () => {