@salesforcedevs/dx-components 0.59.0-avatar-button-11 → 0.59.0-avatar-button-14
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/lwc.config.json
CHANGED
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,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
|
-
|
|
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 {
|
|
63
87
|
this.requestUserInfo();
|
|
64
88
|
}
|
|
65
89
|
}
|
|
@@ -70,15 +94,15 @@ export default class AvatarButton extends LightningElement {
|
|
|
70
94
|
}
|
|
71
95
|
|
|
72
96
|
// This handles logout from within this component, rather than from SSO via the SFIDWidget.
|
|
73
|
-
private handleLogout =
|
|
97
|
+
private handleLogout = (isSsoLogout: boolean) => {
|
|
74
98
|
this._didReceiveUserInfo = false;
|
|
75
99
|
this.isLoading = false;
|
|
76
100
|
this.updateAvatarWithUserInfo({}); // clear old info
|
|
77
101
|
|
|
78
|
-
if (!isSsoLogout && window.SFIDWidget) {
|
|
79
|
-
// If the SFIDWidget is around and logout was not *already*
|
|
80
|
-
// defer to the SFIDWidget. This will ensure that the SSO
|
|
81
|
-
// well.
|
|
102
|
+
if (!isSsoLogout && window.SFIDWidget?.openid_response) {
|
|
103
|
+
// If the SFIDWidget is around and has an access token, and if logout was not *already*
|
|
104
|
+
// triggered by SSO logout, defer to the SFIDWidget. This will ensure that the SSO
|
|
105
|
+
// session is logged out as well.
|
|
82
106
|
window.SFIDWidget.logout();
|
|
83
107
|
} else {
|
|
84
108
|
// Always clear the session token; if not SSO logout, this will also revoke the token with
|
|
@@ -94,7 +118,8 @@ export default class AvatarButton extends LightningElement {
|
|
|
94
118
|
|
|
95
119
|
// This will only be called for "seamless SSO" login by the embedded login widget (SFIDWidget) on the website, if it exists.
|
|
96
120
|
private handleSsoLogin = async (event: Event) => {
|
|
97
|
-
const
|
|
121
|
+
const { userInfo } = (event as CustomEvent).detail;
|
|
122
|
+
const token = userInfo?.access_token;
|
|
98
123
|
|
|
99
124
|
// `token` should always be defined if an SSO login occurs, but we check for extra safety
|
|
100
125
|
if (token) {
|
|
@@ -113,16 +138,14 @@ export default class AvatarButton extends LightningElement {
|
|
|
113
138
|
})
|
|
114
139
|
});
|
|
115
140
|
} catch (ex) {
|
|
116
|
-
|
|
117
|
-
this.updateAvatarWithUserInfo(this.userInfo);
|
|
118
|
-
console.error(ex);
|
|
119
|
-
return;
|
|
141
|
+
console.error(`Attempt to update token failed: ${ex}`);
|
|
120
142
|
}
|
|
121
143
|
}
|
|
122
144
|
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
145
|
+
if (userInfo) {
|
|
146
|
+
this.updateAvatarWithUserInfo(userInfo);
|
|
147
|
+
this._didReceiveUserInfo = true;
|
|
148
|
+
}
|
|
126
149
|
};
|
|
127
150
|
|
|
128
151
|
private handleComponentLogin = () => {
|
|
@@ -160,7 +183,7 @@ export default class AvatarButton extends LightningElement {
|
|
|
160
183
|
}
|
|
161
184
|
} catch (ex) {
|
|
162
185
|
// TODO: Something not directly related to auth went wrong. Unsure what to do here.
|
|
163
|
-
console.error(
|
|
186
|
+
console.error(`Could not request user info: ${ex}`);
|
|
164
187
|
}
|
|
165
188
|
|
|
166
189
|
this.isLoading = false;
|