@0xchain/header 1.1.0-beta.47 → 1.1.0-beta.49
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/index.js +5 -3
- package/dist/lib/Nav.js +29 -13
- package/dist/lib/events.js +0 -4
- package/package.json +14 -14
package/dist/index.js
CHANGED
|
@@ -5,6 +5,7 @@ import Right, { HeaderSource } from "./lib/Right.js";
|
|
|
5
5
|
import Logo from "./lib/Logo.js";
|
|
6
6
|
import { cookies } from "next/headers";
|
|
7
7
|
import { HeaderProvider } from "./lib/context.js";
|
|
8
|
+
import { createSessionFromCookieGetter } from "@0xchain/auth";
|
|
8
9
|
import { USER_EVENTS, emitUserEvent, onUserEvent } from "./lib/events.js";
|
|
9
10
|
async function HeaderBar({
|
|
10
11
|
extra,
|
|
@@ -21,9 +22,10 @@ async function HeaderBar({
|
|
|
21
22
|
if (brand !== "CHAINDIGG") {
|
|
22
23
|
try {
|
|
23
24
|
const cookieStore = await cookies();
|
|
24
|
-
const
|
|
25
|
-
|
|
26
|
-
|
|
25
|
+
const session = createSessionFromCookieGetter(
|
|
26
|
+
(key) => cookieStore.get(key)?.value ?? null
|
|
27
|
+
);
|
|
28
|
+
if (session.isLoggedIn) {
|
|
27
29
|
try {
|
|
28
30
|
userInfo = await request.get("/v2/users/profile", {
|
|
29
31
|
baseURL: process.env.AUTH_INNER_API_URL
|
package/dist/lib/Nav.js
CHANGED
|
@@ -10,15 +10,15 @@ import { useLocale } from "@0xchain/i18n/react";
|
|
|
10
10
|
import Logout from "./User/Logout.js";
|
|
11
11
|
import { useState, useCallback, useEffect } from "react";
|
|
12
12
|
import SignIn from "./User/SignIn.js";
|
|
13
|
-
import {
|
|
14
|
-
import { onUserEvent, USER_EVENTS
|
|
13
|
+
import { getRuntimeLoginState } from "@0xchain/auth";
|
|
14
|
+
import { onUserEvent, USER_EVENTS } from "./events.js";
|
|
15
15
|
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
19
|
function Nav({ onClick = () => void 0, hideNews = false, hideLogin = false, user }) {
|
|
20
20
|
const isChaindigg = useIsChaindigg();
|
|
21
|
-
const { gotoAISQL, gotoChat } = BetterLink();
|
|
21
|
+
const { gotoAISQL, gotoChat, gotoExplorer } = BetterLink();
|
|
22
22
|
const locale = useLocale();
|
|
23
23
|
const pathname = usePathname();
|
|
24
24
|
const [userKey, setUserKey] = useState("");
|
|
@@ -45,6 +45,7 @@ function Nav({ onClick = () => void 0, hideNews = false, hideLogin = false, user
|
|
|
45
45
|
},
|
|
46
46
|
{
|
|
47
47
|
key: "/explorer",
|
|
48
|
+
href: gotoExplorer({ locale }),
|
|
48
49
|
label: /* @__PURE__ */ jsx(Explorer, { onClick, onExpandChange: setExplorerExpanded }),
|
|
49
50
|
show: (pathname2) => {
|
|
50
51
|
return pathname2.includes(`/explorer`);
|
|
@@ -100,22 +101,37 @@ function Nav({ onClick = () => void 0, hideNews = false, hideLogin = false, user
|
|
|
100
101
|
}
|
|
101
102
|
];
|
|
102
103
|
const NavList = isChaindigg ? chaindiggNavList : ichaingoNavList;
|
|
103
|
-
const updateUserInfo = useCallback(() => {
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
resolve(res);
|
|
104
|
+
const updateUserInfo = useCallback(async () => {
|
|
105
|
+
try {
|
|
106
|
+
const response = await fetch("/api/auth/profile", {
|
|
107
|
+
credentials: "include",
|
|
108
|
+
cache: "no-store"
|
|
109
109
|
});
|
|
110
|
-
|
|
110
|
+
if (!response.ok) {
|
|
111
|
+
throw new Error(`Failed to load profile: ${response.status}`);
|
|
112
|
+
}
|
|
113
|
+
const res = await response.json();
|
|
114
|
+
setUserInfo(res || {});
|
|
115
|
+
setUserKey((/* @__PURE__ */ new Date()).getTime().toString());
|
|
116
|
+
return res;
|
|
117
|
+
} catch (error) {
|
|
118
|
+
console.error(error);
|
|
119
|
+
setUserInfo({});
|
|
120
|
+
return null;
|
|
121
|
+
}
|
|
111
122
|
}, []);
|
|
112
123
|
useEffect(() => {
|
|
113
124
|
if (isChaindigg) return;
|
|
114
|
-
onUserEvent(USER_EVENTS.PROFILE_UPDATED, updateUserInfo);
|
|
125
|
+
const cleanProfileUpdated = onUserEvent(USER_EVENTS.PROFILE_UPDATED, updateUserInfo);
|
|
126
|
+
const cleanLoggedIn = onUserEvent(USER_EVENTS.LOGGED_IN, updateUserInfo);
|
|
127
|
+
if (!userInfo?.id && getRuntimeLoginState() === true) {
|
|
128
|
+
updateUserInfo();
|
|
129
|
+
}
|
|
115
130
|
return () => {
|
|
116
|
-
|
|
131
|
+
cleanProfileUpdated();
|
|
132
|
+
cleanLoggedIn();
|
|
117
133
|
};
|
|
118
|
-
}, [isChaindigg]);
|
|
134
|
+
}, [isChaindigg, updateUserInfo, userInfo?.id]);
|
|
119
135
|
if (isChaindigg) {
|
|
120
136
|
return /* @__PURE__ */ jsxs(
|
|
121
137
|
"nav",
|
package/dist/lib/events.js
CHANGED
|
@@ -15,12 +15,8 @@ function onUserEvent(eventName, callback) {
|
|
|
15
15
|
window.addEventListener(eventName, handler);
|
|
16
16
|
return () => window.removeEventListener(eventName, handler);
|
|
17
17
|
}
|
|
18
|
-
function cleanUserEvent(type, handler) {
|
|
19
|
-
window.removeEventListener(type, handler);
|
|
20
|
-
}
|
|
21
18
|
export {
|
|
22
19
|
USER_EVENTS,
|
|
23
|
-
cleanUserEvent,
|
|
24
20
|
emitUserEvent,
|
|
25
21
|
onUserEvent
|
|
26
22
|
};
|
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.49",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"main": "./dist/index.js",
|
|
6
6
|
"module": "./dist/index.js",
|
|
@@ -42,19 +42,19 @@
|
|
|
42
42
|
"tailwind-merge": "3.3.1"
|
|
43
43
|
},
|
|
44
44
|
"dependencies": {
|
|
45
|
-
"@0xchain/i18n": "1.1.0-beta.
|
|
46
|
-
"@0xchain/
|
|
47
|
-
"@0xchain/
|
|
48
|
-
"@0xchain/
|
|
49
|
-
"@0xchain/
|
|
50
|
-
"@0xchain/
|
|
51
|
-
"@0xchain/
|
|
52
|
-
"@0xchain/
|
|
53
|
-
"@0xchain/
|
|
54
|
-
"@0xchain/
|
|
55
|
-
"@0xchain/
|
|
56
|
-
"@0xchain/tooltip": "1.1.0-beta.
|
|
57
|
-
"@0xchain/
|
|
45
|
+
"@0xchain/i18n": "1.1.0-beta.49",
|
|
46
|
+
"@0xchain/link": "1.1.0-beta.49",
|
|
47
|
+
"@0xchain/image": "1.1.0-beta.49",
|
|
48
|
+
"@0xchain/translation": "1.1.0-beta.49",
|
|
49
|
+
"@0xchain/iconfont": "1.1.0-beta.49",
|
|
50
|
+
"@0xchain/request": "1.1.0-beta.49",
|
|
51
|
+
"@0xchain/ui": "1.1.0-beta.49",
|
|
52
|
+
"@0xchain/auth": "1.1.0-beta.49",
|
|
53
|
+
"@0xchain/with-login": "1.1.0-beta.49",
|
|
54
|
+
"@0xchain/better-link": "1.1.0-beta.49",
|
|
55
|
+
"@0xchain/avatar": "1.1.0-beta.49",
|
|
56
|
+
"@0xchain/tooltip": "1.1.0-beta.49",
|
|
57
|
+
"@0xchain/theme-toggle": "1.1.0-beta.49"
|
|
58
58
|
},
|
|
59
59
|
"nx": {
|
|
60
60
|
"tags": [
|