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

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-9",
4
4
  "description": "DX Lightning web components",
5
5
  "license": "MIT",
6
6
  "engines": {
@@ -91,23 +91,36 @@ 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
+ headers: {
107
+ "Content-Type": "application/json"
108
+ },
109
+ body: JSON.stringify({
110
+ token
111
+ })
108
112
  });
113
+ } catch (ex) {
114
+ // If the request fails for some reason, fall back to whatever we've got
115
+ this.updateAvatarWithUserInfo(this.userInfo);
116
+ console.error(ex);
117
+ return;
109
118
  }
110
119
  }
120
+
121
+ // Unfortunately, the user info provided by the SFIDWidget on SSO login does not contain
122
+ // image URLs, so we also have to request it manually again
123
+ this.requestUserInfo();
111
124
  };
112
125
 
113
126
  private handleComponentLogin = () => {