@0xchain/header 1.1.0-beta.58 → 1.1.0-beta.59
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/dist/lib/Nav.js +6 -13
- package/dist/lib/User/MainTrigger.js +2 -1
- package/dist/lib/User/index.js +2 -1
- package/dist/lib/authProfile.js +34 -0
- package/package.json +15 -15
package/dist/lib/Nav.js
CHANGED
|
@@ -16,6 +16,7 @@ import { usePathname } from "next/navigation";
|
|
|
16
16
|
import Explorer from "./Explorer.js";
|
|
17
17
|
import Products from "./Products.js";
|
|
18
18
|
import { useIsChaindigg } from "./context.js";
|
|
19
|
+
import { hasProfileIdentity, fetchHeaderProfile } from "./authProfile.js";
|
|
19
20
|
function Nav({ onClick = () => void 0, hideNews = false, hideLogin = false, user }) {
|
|
20
21
|
const isChaindigg = useIsChaindigg();
|
|
21
22
|
const { gotoAISQL, gotoChat } = BetterLink();
|
|
@@ -23,6 +24,7 @@ function Nav({ onClick = () => void 0, hideNews = false, hideLogin = false, user
|
|
|
23
24
|
const pathname = usePathname();
|
|
24
25
|
const [userKey, setUserKey] = useState("");
|
|
25
26
|
const [userInfo, setUserInfo] = useState(user);
|
|
27
|
+
const hasUserProfile = hasProfileIdentity(userInfo);
|
|
26
28
|
const [, setExplorerExpanded] = useState(false);
|
|
27
29
|
const ichaingoNavList = [
|
|
28
30
|
{
|
|
@@ -105,16 +107,7 @@ function Nav({ onClick = () => void 0, hideNews = false, hideLogin = false, user
|
|
|
105
107
|
const NavList = isChaindigg ? chaindiggNavList : ichaingoNavList;
|
|
106
108
|
const updateUserInfo = useCallback(async () => {
|
|
107
109
|
try {
|
|
108
|
-
const
|
|
109
|
-
const profileUrl = appUrl ? `${appUrl}/api/auth/profile` : "/api/auth/profile";
|
|
110
|
-
const response = await fetch(profileUrl, {
|
|
111
|
-
credentials: "include",
|
|
112
|
-
cache: "no-store"
|
|
113
|
-
});
|
|
114
|
-
if (!response.ok) {
|
|
115
|
-
throw new Error(`Failed to load profile: ${response.status}`);
|
|
116
|
-
}
|
|
117
|
-
const profile = await response.json();
|
|
110
|
+
const profile = await fetchHeaderProfile();
|
|
118
111
|
setUserInfo(profile || {});
|
|
119
112
|
setUserKey((/* @__PURE__ */ new Date()).getTime().toString());
|
|
120
113
|
return profile;
|
|
@@ -128,14 +121,14 @@ function Nav({ onClick = () => void 0, hideNews = false, hideLogin = false, user
|
|
|
128
121
|
if (isChaindigg) return;
|
|
129
122
|
const cleanProfileUpdated = onUserEvent(USER_EVENTS.PROFILE_UPDATED, updateUserInfo);
|
|
130
123
|
const cleanLoggedIn = onUserEvent(USER_EVENTS.LOGGED_IN, updateUserInfo);
|
|
131
|
-
if (!
|
|
124
|
+
if (!hasUserProfile && getRuntimeLoginState() === true) {
|
|
132
125
|
updateUserInfo();
|
|
133
126
|
}
|
|
134
127
|
return () => {
|
|
135
128
|
cleanProfileUpdated();
|
|
136
129
|
cleanLoggedIn();
|
|
137
130
|
};
|
|
138
|
-
}, [isChaindigg, updateUserInfo
|
|
131
|
+
}, [hasUserProfile, isChaindigg, updateUserInfo]);
|
|
139
132
|
if (isChaindigg) {
|
|
140
133
|
return /* @__PURE__ */ jsxs(
|
|
141
134
|
"nav",
|
|
@@ -237,7 +230,7 @@ function Nav({ onClick = () => void 0, hideNews = false, hideLogin = false, user
|
|
|
237
230
|
/* @__PURE__ */ jsx(Setting, { onClick }),
|
|
238
231
|
!pathname.includes("/login") && !hideLogin ? /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
239
232
|
/* @__PURE__ */ jsx(UserControl, { onClick, userInfo }, userKey),
|
|
240
|
-
|
|
233
|
+
hasUserProfile ? /* @__PURE__ */ jsx("div", { className: "flex md:hidden h-11 md:h-auto cursor-pointer whitespace-nowrap order-3 bg-background rounded-lg p-2 mt-3 w-full items-center justify-center text-muted-foreground", children: /* @__PURE__ */ jsx(Logout, {}) }) : /* @__PURE__ */ jsx(
|
|
241
234
|
SignIn,
|
|
242
235
|
{
|
|
243
236
|
onClick,
|
|
@@ -6,6 +6,7 @@ import Translation from "@0xchain/translation";
|
|
|
6
6
|
import BetterLink from "@0xchain/better-link";
|
|
7
7
|
import { useLocale } from "@0xchain/i18n/react";
|
|
8
8
|
import Avatar from "@0xchain/avatar";
|
|
9
|
+
import { hasProfileIdentity } from "../authProfile.js";
|
|
9
10
|
function MainTrigger({
|
|
10
11
|
userInfo
|
|
11
12
|
}) {
|
|
@@ -13,7 +14,7 @@ function MainTrigger({
|
|
|
13
14
|
const [link, setLink] = useState("");
|
|
14
15
|
const locale = useLocale();
|
|
15
16
|
const isLogin = useMemo(() => {
|
|
16
|
-
return userInfo
|
|
17
|
+
return hasProfileIdentity(userInfo);
|
|
17
18
|
}, [userInfo]);
|
|
18
19
|
useEffect(() => {
|
|
19
20
|
setLink(gotoLogin({
|
package/dist/lib/User/index.js
CHANGED
|
@@ -4,6 +4,7 @@ import PC from "./Pc.js";
|
|
|
4
4
|
import Mobile from "./Mobile.js";
|
|
5
5
|
import { twMerge } from "tailwind-merge";
|
|
6
6
|
import SignIn from "./SignIn.js";
|
|
7
|
+
import { hasProfileIdentity } from "../authProfile.js";
|
|
7
8
|
const list = [
|
|
8
9
|
{
|
|
9
10
|
name: "overview",
|
|
@@ -27,7 +28,7 @@ const list = [
|
|
|
27
28
|
}
|
|
28
29
|
];
|
|
29
30
|
function UserControl({ onClick = (e) => void 0, className, userInfo }) {
|
|
30
|
-
if (!userInfo
|
|
31
|
+
if (!hasProfileIdentity(userInfo)) {
|
|
31
32
|
return /* @__PURE__ */ jsx(SignIn, { onClick, className: twMerge(
|
|
32
33
|
"hidden md:flex cursor-pointer text-sm text-white bg-primary py-2 px-3 rounded-lg",
|
|
33
34
|
"order-3"
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
function hasProfileIdentity(userInfo) {
|
|
2
|
+
return Boolean(userInfo?.id || userInfo?.userId);
|
|
3
|
+
}
|
|
4
|
+
function getProfileUrls() {
|
|
5
|
+
const urls = ["/api/auth/profile"];
|
|
6
|
+
const appUrl = (process.env.NEXT_PUBLIC_APP_URL || "").replace(/\/$/, "");
|
|
7
|
+
if (appUrl) {
|
|
8
|
+
urls.push(`${appUrl}/api/auth/profile`);
|
|
9
|
+
}
|
|
10
|
+
return Array.from(new Set(urls));
|
|
11
|
+
}
|
|
12
|
+
async function fetchHeaderProfile(fetcher = fetch) {
|
|
13
|
+
let lastError = null;
|
|
14
|
+
for (const profileUrl of getProfileUrls()) {
|
|
15
|
+
try {
|
|
16
|
+
const response = await fetcher(profileUrl, {
|
|
17
|
+
credentials: "include",
|
|
18
|
+
cache: "no-store"
|
|
19
|
+
});
|
|
20
|
+
if (!response.ok) {
|
|
21
|
+
throw new Error(`Failed to load profile: ${response.status}`);
|
|
22
|
+
}
|
|
23
|
+
return await response.json();
|
|
24
|
+
} catch (error) {
|
|
25
|
+
lastError = error;
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
throw lastError instanceof Error ? lastError : new Error("Failed to load profile");
|
|
29
|
+
}
|
|
30
|
+
export {
|
|
31
|
+
fetchHeaderProfile,
|
|
32
|
+
getProfileUrls,
|
|
33
|
+
hasProfileIdentity
|
|
34
|
+
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@0xchain/header",
|
|
3
|
-
"version": "1.1.0-beta.
|
|
3
|
+
"version": "1.1.0-beta.59",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"main": "./dist/index.js",
|
|
6
6
|
"module": "./dist/index.js",
|
|
@@ -26,7 +26,7 @@
|
|
|
26
26
|
"react": "19.1.1",
|
|
27
27
|
"react-dom": "19.1.1",
|
|
28
28
|
"tailwind-merge": "3.3.1",
|
|
29
|
-
"@0xchain/with-login": "1.1.0-beta.
|
|
29
|
+
"@0xchain/with-login": "1.1.0-beta.59"
|
|
30
30
|
},
|
|
31
31
|
"devDependencies": {
|
|
32
32
|
"@0xchain/next-themes": "1.0.0",
|
|
@@ -41,21 +41,21 @@
|
|
|
41
41
|
"react-dom": "19.1.1",
|
|
42
42
|
"rollup-plugin-preserve-use-client": "3.0.1",
|
|
43
43
|
"tailwind-merge": "3.3.1",
|
|
44
|
-
"@0xchain/with-login": "1.1.0-beta.
|
|
44
|
+
"@0xchain/with-login": "1.1.0-beta.59"
|
|
45
45
|
},
|
|
46
46
|
"dependencies": {
|
|
47
|
-
"@0xchain/auth": "1.1.0-beta.
|
|
48
|
-
"@0xchain/
|
|
49
|
-
"@0xchain/
|
|
50
|
-
"@0xchain/
|
|
51
|
-
"@0xchain/
|
|
52
|
-
"@0xchain/
|
|
53
|
-
"@0xchain/
|
|
54
|
-
"@0xchain/
|
|
55
|
-
"@0xchain/
|
|
56
|
-
"@0xchain/translation": "1.1.0-beta.
|
|
57
|
-
"@0xchain/
|
|
58
|
-
"@0xchain/
|
|
47
|
+
"@0xchain/auth": "1.1.0-beta.59",
|
|
48
|
+
"@0xchain/better-link": "1.1.0-beta.59",
|
|
49
|
+
"@0xchain/i18n": "1.1.0-beta.59",
|
|
50
|
+
"@0xchain/avatar": "1.1.0-beta.59",
|
|
51
|
+
"@0xchain/link": "1.1.0-beta.59",
|
|
52
|
+
"@0xchain/iconfont": "1.1.0-beta.59",
|
|
53
|
+
"@0xchain/request": "1.1.0-beta.59",
|
|
54
|
+
"@0xchain/image": "1.1.0-beta.59",
|
|
55
|
+
"@0xchain/theme-toggle": "1.1.0-beta.59",
|
|
56
|
+
"@0xchain/translation": "1.1.0-beta.59",
|
|
57
|
+
"@0xchain/ui": "1.1.0-beta.59",
|
|
58
|
+
"@0xchain/tooltip": "1.1.0-beta.59"
|
|
59
59
|
},
|
|
60
60
|
"nx": {
|
|
61
61
|
"tags": [
|