@salesforcedevs/dx-components 0.55.3-alpha-1 → 0.55.3-alpha-2
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,30 +1,32 @@
|
|
|
1
1
|
<template>
|
|
2
|
-
<div if:
|
|
2
|
+
<div if:true={isLoggedIn}>
|
|
3
3
|
<dx-popover offset="small" width="320px" open-on-hover>
|
|
4
4
|
<img
|
|
5
5
|
slot="control"
|
|
6
|
-
src=
|
|
6
|
+
src={userInfo.avatarImgSrc}
|
|
7
7
|
class="avatar avatar-small"
|
|
8
8
|
/>
|
|
9
9
|
<div slot="content">
|
|
10
10
|
<div class="login-container logged-in">
|
|
11
|
-
<img src=
|
|
11
|
+
<img src="/assets/svg/login-widget-bg.png" class="header-img" />
|
|
12
12
|
<img
|
|
13
|
-
src=
|
|
13
|
+
src={userInfo.avatarImgSrc}
|
|
14
14
|
class="avatar avatar-medium"
|
|
15
15
|
/>
|
|
16
|
-
<span class="heading">
|
|
17
|
-
<span class="sub-heading">
|
|
16
|
+
<span class="heading">{userInfo.fullName}</span>
|
|
17
|
+
<span class="sub-heading">{userInfo.username}</span>
|
|
18
18
|
<div class="heading-links">
|
|
19
|
+
<!--
|
|
19
20
|
<a href="#" class="inline-link">Switch account</a>
|
|
20
21
|
|
|
|
21
|
-
|
|
22
|
+
-->
|
|
23
|
+
<a href={logoutUrl} class="inline-link">Logout</a>
|
|
22
24
|
</div>
|
|
23
25
|
<div class="login-section">
|
|
24
26
|
<span class="login-section-title">Trailblazer.me</span>
|
|
25
27
|
<ul>
|
|
26
28
|
<li class="login-list-item">
|
|
27
|
-
<a href=
|
|
29
|
+
<a href={settingsUrl} class="login-link">
|
|
28
30
|
<span class="login-link-label">
|
|
29
31
|
Settings
|
|
30
32
|
</span>
|
|
@@ -36,7 +38,7 @@
|
|
|
36
38
|
</a>
|
|
37
39
|
</li>
|
|
38
40
|
<li class="login-list-item">
|
|
39
|
-
<a href=
|
|
41
|
+
<a href={profileUrl} class="login-link">
|
|
40
42
|
<span class="login-link-label">
|
|
41
43
|
Profile
|
|
42
44
|
</span>
|
|
@@ -59,7 +61,7 @@
|
|
|
59
61
|
></dx-icon>
|
|
60
62
|
</a>
|
|
61
63
|
<div class="login-link-blurb">
|
|
62
|
-
Our Developer Forums have a new home
|
|
64
|
+
Our Developer Forums have a new home!
|
|
63
65
|
<a href="#" class="inline-link">
|
|
64
66
|
Learn more
|
|
65
67
|
</a>
|
|
@@ -71,13 +73,14 @@
|
|
|
71
73
|
</div>
|
|
72
74
|
</dx-popover>
|
|
73
75
|
</div>
|
|
74
|
-
<div if:
|
|
76
|
+
<div if:false={isLoggedIn}>
|
|
75
77
|
<dx-popover offset="small" width="320px" open-on-hover>
|
|
76
78
|
<dx-button
|
|
77
|
-
class="login-control"
|
|
78
79
|
slot="control"
|
|
80
|
+
class="login-control"
|
|
79
81
|
icon-symbol="user"
|
|
80
82
|
icon-position="left"
|
|
83
|
+
loading={isLoading}
|
|
81
84
|
variant="custom"
|
|
82
85
|
>
|
|
83
86
|
Login
|
|
@@ -125,7 +128,7 @@
|
|
|
125
128
|
</span>
|
|
126
129
|
<ul>
|
|
127
130
|
<li class="login-list-item">
|
|
128
|
-
<a href=
|
|
131
|
+
<a href={loginUrl} class="login-link">
|
|
129
132
|
<span class="login-link-label">
|
|
130
133
|
Trailblazer.me
|
|
131
134
|
</span>
|
|
@@ -1,34 +1,45 @@
|
|
|
1
|
-
import { api, LightningElement
|
|
1
|
+
import { api, LightningElement } from "lwc";
|
|
2
2
|
import Cookie from "js-cookie";
|
|
3
|
-
// import oauth2 from "salesforce-oauth2";
|
|
4
3
|
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
const TBID_AUTH_URL = "https://tbid-auth-app-dev.herokuapp.com/tbid/dologin";
|
|
10
|
-
const TBID_USERINFO_URL =
|
|
11
|
-
"https://dev1-trailblazer-identity.cs192.force.com/services/oauth2/userinfo";
|
|
4
|
+
const TBID_BASE_URL = "https://dev1-trailblazer-identity.cs192.force.com";
|
|
5
|
+
const TBID_LOGIN_URL = "https://development.developer.salesforce.com/tbid/dologin";
|
|
6
|
+
const TBID_LOGOUT_URL = `${TBID_BASE_URL}/services/auth/idp/oidc/logout`;
|
|
7
|
+
const TBID_USERINFO_URL = `${TBID_BASE_URL}/services/oauth2/userinfo`;
|
|
12
8
|
|
|
13
9
|
export interface UserInfo {
|
|
14
10
|
avatarImgSrc?: string;
|
|
15
11
|
firstName?: string;
|
|
16
12
|
lastName?: string;
|
|
17
13
|
username?: string;
|
|
14
|
+
readonly fullName: string;
|
|
18
15
|
}
|
|
19
16
|
|
|
20
17
|
export default class AvatarButton extends LightningElement {
|
|
21
18
|
@api size: "small" | "medium" | "large" = "medium";
|
|
22
19
|
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
20
|
+
private userInfo: UserInfo = {
|
|
21
|
+
get fullName() {
|
|
22
|
+
if (this.firstName && this.lastName) {
|
|
23
|
+
return `${this.firstName} ${this.lastName}`;
|
|
24
|
+
}
|
|
25
|
+
return this.firstName || this.lastName || "";
|
|
26
|
+
}
|
|
27
|
+
};
|
|
28
|
+
private isLoading = false;
|
|
29
|
+
private settingsUrl = `${TBID_BASE_URL}/settings`;
|
|
30
|
+
private profileUrl = `${TBID_BASE_URL}/id`;
|
|
31
|
+
private loginUrl = TBID_LOGIN_URL;
|
|
32
|
+
private logoutUrl = TBID_LOGOUT_URL;
|
|
27
33
|
|
|
34
|
+
// A user only counts as logged in for our purposes if they have an access token
|
|
35
|
+
// and we have successfully used it to get their info.
|
|
28
36
|
private get isLoggedIn() {
|
|
29
|
-
return Boolean(this._tbidAccessToken);
|
|
37
|
+
return Boolean(this._tbidAccessToken) && this._didReceiveUserInfo;
|
|
30
38
|
}
|
|
31
39
|
|
|
40
|
+
private _didReceiveUserInfo = false;
|
|
41
|
+
private _tbidAccessToken: string | undefined;
|
|
42
|
+
|
|
32
43
|
connectedCallback() {
|
|
33
44
|
this._tbidAccessToken = Cookie.get("TBID");
|
|
34
45
|
|
|
@@ -37,42 +48,52 @@ export default class AvatarButton extends LightningElement {
|
|
|
37
48
|
}
|
|
38
49
|
}
|
|
39
50
|
|
|
40
|
-
|
|
41
|
-
if (!
|
|
42
|
-
|
|
51
|
+
private updateAvatarWithUserInfo(userInfo: any) {
|
|
52
|
+
if (!userInfo) {
|
|
53
|
+
return;
|
|
43
54
|
}
|
|
44
|
-
}
|
|
45
55
|
|
|
46
|
-
|
|
47
|
-
this.userInfo.
|
|
56
|
+
this.userInfo.avatarImgSrc = userInfo.photos?.thumbnail;
|
|
57
|
+
this.userInfo.firstName = userInfo.given_name;
|
|
58
|
+
this.userInfo.lastName = userInfo.family_name;
|
|
59
|
+
this.userInfo.username = userInfo.preferred_username;
|
|
48
60
|
// TODO: Consider displaying initials if no photo. Is there always a photo?
|
|
49
61
|
}
|
|
50
62
|
|
|
51
63
|
private async requestUserInfo(accessToken: string) {
|
|
52
|
-
this.
|
|
64
|
+
this.isLoading = true;
|
|
53
65
|
|
|
54
66
|
try {
|
|
55
67
|
// FIXME: The TBID userinfo currently only accepts the access token in the URL
|
|
56
68
|
// as a query parameter. This is bad, but they're aware of it, and when it is
|
|
57
69
|
// fixed, we should use a header or something instead.
|
|
58
70
|
const userInfoRes = await fetch(
|
|
59
|
-
TBID_USERINFO_URL +
|
|
71
|
+
TBID_USERINFO_URL +
|
|
72
|
+
"?access_token=" +
|
|
73
|
+
encodeURIComponent(accessToken)
|
|
60
74
|
);
|
|
61
75
|
|
|
62
76
|
if (userInfoRes.ok) {
|
|
63
77
|
const userInfo = await userInfoRes.json();
|
|
64
78
|
this.updateAvatarWithUserInfo(userInfo);
|
|
79
|
+
this._didReceiveUserInfo = true;
|
|
65
80
|
} else {
|
|
66
81
|
if (userInfoRes.status === 403) {
|
|
67
|
-
|
|
82
|
+
const refreshToken = Cookie.get('TBID_REFRESH');
|
|
83
|
+
if (refreshToken) {
|
|
84
|
+
console.log('Would use refresh token');
|
|
85
|
+
}
|
|
68
86
|
}
|
|
87
|
+
// TODO: Do we want a "something went wrong" state here?
|
|
69
88
|
}
|
|
70
89
|
} catch (ex) {
|
|
71
90
|
// TODO: Something not directly related to auth went wrong. Unsure what to do here.
|
|
72
91
|
}
|
|
73
92
|
|
|
74
|
-
this.
|
|
93
|
+
this.isLoading = false;
|
|
75
94
|
}
|
|
76
95
|
|
|
77
|
-
private
|
|
96
|
+
// private refreshAccessToken(refreshToken);
|
|
97
|
+
|
|
98
|
+
// private handleAuthFailure() {}
|
|
78
99
|
}
|