@salesforcedevs/dx-components 0.59.0-avatar-button-4 → 0.59.0-avatar-button-5
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
|
@@ -21,7 +21,11 @@
|
|
|
21
21
|
<a href="#" class="inline-link">Switch account</a>
|
|
22
22
|
|
|
|
23
23
|
-->
|
|
24
|
-
<a
|
|
24
|
+
<a
|
|
25
|
+
href="#"
|
|
26
|
+
onclick={handleComponentLogout}
|
|
27
|
+
class="inline-link"
|
|
28
|
+
>
|
|
25
29
|
Logout
|
|
26
30
|
</a>
|
|
27
31
|
</div>
|
|
@@ -40,7 +40,7 @@ export default class AvatarButton extends LightningElement {
|
|
|
40
40
|
|
|
41
41
|
connectedCallback() {
|
|
42
42
|
window.addEventListener("tbid-login", this.handleSsoLogin);
|
|
43
|
-
window.addEventListener("tbid-logout", this.
|
|
43
|
+
window.addEventListener("tbid-logout", this.handleSsoLogout);
|
|
44
44
|
|
|
45
45
|
// Whenever this component is added to the DOM, immediately request user info; if the user is logged in
|
|
46
46
|
// and we receive the info, this component will display the avatar UI; otherwise, it will display the login
|
|
@@ -50,29 +50,33 @@ export default class AvatarButton extends LightningElement {
|
|
|
50
50
|
|
|
51
51
|
disconnectedCallback() {
|
|
52
52
|
window.removeEventListener("tbid-login", this.handleSsoLogin);
|
|
53
|
-
window.removeEventListener("tbid-logout", this.
|
|
53
|
+
window.removeEventListener("tbid-logout", this.handleSsoLogout);
|
|
54
54
|
}
|
|
55
55
|
|
|
56
|
-
// This
|
|
57
|
-
private
|
|
56
|
+
// This handles logout from within this component, rather than from SSO via the SFIDWidget.
|
|
57
|
+
private handleLogout = async (isSsoLogout: boolean) => {
|
|
58
|
+
this._didReceiveUserInfo = false;
|
|
59
|
+
this.isLoading = false;
|
|
60
|
+
this.updateAvatarWithUserInfo({}); // clear old info
|
|
61
|
+
|
|
62
|
+
fetch(`${TBID_API_LOGOUT_URL}?isSsoLogout=${isSsoLogout}`); // no need to await this
|
|
63
|
+
};
|
|
64
|
+
|
|
65
|
+
// This will only be called for "seamless SSO" login by the embedded login widget (SFIDWidget) on the website, if it exists.
|
|
66
|
+
private handleSsoLogin = (event: Event) => {
|
|
58
67
|
const userInfo = (event as CustomEvent).detail;
|
|
59
68
|
if (userInfo) {
|
|
60
69
|
this.updateAvatarWithUserInfo(userInfo);
|
|
61
70
|
this._didReceiveUserInfo = true;
|
|
62
71
|
}
|
|
63
|
-
}
|
|
72
|
+
};
|
|
64
73
|
|
|
65
|
-
// This
|
|
66
|
-
|
|
67
|
-
private async handleLogout() {
|
|
68
|
-
this._didReceiveUserInfo = false;
|
|
69
|
-
this.isLoading = false;
|
|
70
|
-
this.updateAvatarWithUserInfo({}); // clear old info
|
|
74
|
+
// This will only be called for "seamless SSO" login by the embedded login widget (SFIDWidget) on the website, if it exists.
|
|
75
|
+
private handleSsoLogout = this.handleLogout.bind(this, true);
|
|
71
76
|
|
|
72
|
-
|
|
73
|
-
}
|
|
77
|
+
private handleComponentLogout = this.handleLogout.bind(this, false);
|
|
74
78
|
|
|
75
|
-
private updateAvatarWithUserInfo(userInfo: any) {
|
|
79
|
+
private updateAvatarWithUserInfo = (userInfo: any) => {
|
|
76
80
|
if (!userInfo) {
|
|
77
81
|
return;
|
|
78
82
|
}
|
|
@@ -82,9 +86,9 @@ export default class AvatarButton extends LightningElement {
|
|
|
82
86
|
this.userInfo.lastName = userInfo.family_name;
|
|
83
87
|
this.userInfo.username = userInfo.preferred_username;
|
|
84
88
|
// TODO: Consider displaying initials if no photo. Is there always a photo?
|
|
85
|
-
}
|
|
89
|
+
};
|
|
86
90
|
|
|
87
|
-
private async
|
|
91
|
+
private requestUserInfo = async () => {
|
|
88
92
|
this.isLoading = true;
|
|
89
93
|
|
|
90
94
|
try {
|
|
@@ -101,5 +105,5 @@ export default class AvatarButton extends LightningElement {
|
|
|
101
105
|
}
|
|
102
106
|
|
|
103
107
|
this.isLoading = false;
|
|
104
|
-
}
|
|
108
|
+
};
|
|
105
109
|
}
|