@salesforcedevs/dx-components 0.59.0-avatar-button-9 → 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 +1 -1
- package/src/modules/dx/avatarButton/avatarButton.ts +38 -13
- package/yarn-error.log +19802 -0
package/package.json
CHANGED
|
@@ -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,37 @@ 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
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
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 {
|
|
87
|
+
this.requestUserInfo();
|
|
88
|
+
}
|
|
63
89
|
}
|
|
64
90
|
|
|
65
91
|
disconnectedCallback() {
|
|
@@ -78,11 +104,11 @@ export default class AvatarButton extends LightningElement {
|
|
|
78
104
|
// defer to the SFIDWidget. This will ensure that the SSO session is logged out as
|
|
79
105
|
// well.
|
|
80
106
|
window.SFIDWidget.logout();
|
|
107
|
+
} else {
|
|
108
|
+
// Always clear the session token; if not SSO logout, this will also revoke the token with
|
|
109
|
+
// TBID; if SSO logout, that step is already taken care of
|
|
110
|
+
fetch(`${TBID_API_LOGOUT_URL}?isSsoLogout=${isSsoLogout}`); // no need to await this
|
|
81
111
|
}
|
|
82
|
-
|
|
83
|
-
// Always clear the session token; if not SSO logout, this will also revoke the token with
|
|
84
|
-
// TBID; if SSO logout, that step is already taken care of
|
|
85
|
-
fetch(`${TBID_API_LOGOUT_URL}?isSsoLogout=${isSsoLogout}`); // no need to await this
|
|
86
112
|
};
|
|
87
113
|
|
|
88
114
|
// This will only be called for "seamless SSO" login by the embedded login widget (SFIDWidget) on the website, if it exists.
|
|
@@ -110,17 +136,16 @@ export default class AvatarButton extends LightningElement {
|
|
|
110
136
|
token
|
|
111
137
|
})
|
|
112
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();
|
|
113
143
|
} catch (ex) {
|
|
114
144
|
// If the request fails for some reason, fall back to whatever we've got
|
|
115
145
|
this.updateAvatarWithUserInfo(this.userInfo);
|
|
116
146
|
console.error(ex);
|
|
117
|
-
return;
|
|
118
147
|
}
|
|
119
148
|
}
|
|
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();
|
|
124
149
|
};
|
|
125
150
|
|
|
126
151
|
private handleComponentLogin = () => {
|