@windrun-huaiin/third-ui 7.4.0 → 7.4.1

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.
@@ -15,7 +15,7 @@ var moneyPriceTypes = require('./money-price-types.js');
15
15
 
16
16
  function MoneyPriceInteractive({ data, config, upgradeApiEndpoint, signInPath }) {
17
17
  const fingerprintContext = fingerprintProvider.useFingerprintContextSafe();
18
- const { redirectToSignIn } = nextjs.useClerk();
18
+ const { redirectToSignIn, user } = nextjs.useClerk();
19
19
  const router = navigation.useRouter();
20
20
  const [billingType, setBillingType] = React.useState(data.billingSwitch.defaultKey);
21
21
  const [isProcessing, setIsProcessing] = React.useState(false);
@@ -38,14 +38,17 @@ function MoneyPriceInteractive({ data, config, upgradeApiEndpoint, signInPath })
38
38
  }, [fingerprintContext]);
39
39
  // 优化 userContext 使用 useMemo
40
40
  const userContext = React.useMemo(() => {
41
- var _a, _b, _c, _d;
42
- return ({
43
- isAuthenticated: !!((_a = fingerprintContext === null || fingerprintContext === void 0 ? void 0 : fingerprintContext.xUser) === null || _a === void 0 ? void 0 : _a.clerkUserId),
44
- subscriptionStatus: getUserState(),
45
- subscriptionType: ((_c = (_b = fingerprintContext === null || fingerprintContext === void 0 ? void 0 : fingerprintContext.xSubscription) === null || _b === void 0 ? void 0 : _b.priceId) === null || _c === void 0 ? void 0 : _c.includes('yearly')) ? 'yearly' : 'monthly',
46
- subscriptionEndDate: (_d = fingerprintContext === null || fingerprintContext === void 0 ? void 0 : fingerprintContext.xSubscription) === null || _d === void 0 ? void 0 : _d.subPeriodEnd
47
- });
48
- }, [fingerprintContext, getUserState]);
41
+ var _a, _b, _c;
42
+ // 使用 Clerk 的 user 对象判断登录状态
43
+ const isAuth = !!(user === null || user === void 0 ? void 0 : user.id);
44
+ const userState = getUserState();
45
+ return {
46
+ isAuthenticated: isAuth,
47
+ subscriptionStatus: isAuth ? userState : moneyPriceTypes.UserState.Anonymous,
48
+ subscriptionType: ((_b = (_a = fingerprintContext === null || fingerprintContext === void 0 ? void 0 : fingerprintContext.xSubscription) === null || _a === void 0 ? void 0 : _a.priceId) === null || _b === void 0 ? void 0 : _b.includes('yearly')) ? 'yearly' : 'monthly',
49
+ subscriptionEndDate: (_c = fingerprintContext === null || fingerprintContext === void 0 ? void 0 : fingerprintContext.xSubscription) === null || _c === void 0 ? void 0 : _c.subPeriodEnd
50
+ };
51
+ }, [user, fingerprintContext, getUserState]);
49
52
  // 处理登录
50
53
  const handleLogin = React.useCallback(() => {
51
54
  if (signInPath) {
@@ -77,6 +80,25 @@ function MoneyPriceInteractive({ data, config, upgradeApiEndpoint, signInPath })
77
80
  provider: config.activeProvider
78
81
  })
79
82
  });
83
+ // 检查是否是重定向或非JSON响应
84
+ if (response.redirected || response.status === 302 || response.status === 301) {
85
+ // 如果是重定向,直接跳转到重定向URL(通常是登录页面)
86
+ window.location.href = response.url;
87
+ return;
88
+ }
89
+ // 检查Content-Type是否为JSON
90
+ const contentType = response.headers.get('content-type');
91
+ if (!contentType || !contentType.includes('application/json')) {
92
+ // 如果不是JSON响应,可能是HTML登录页面,提示用户重新登录
93
+ console.error('Received non-JSON response, user may need to login');
94
+ if (signInPath) {
95
+ window.location.href = signInPath;
96
+ }
97
+ else {
98
+ redirectToSignIn();
99
+ }
100
+ return;
101
+ }
80
102
  const result = yield response.json();
81
103
  if (result.success && ((_a = result.data) === null || _a === void 0 ? void 0 : _a.sessionUrl)) {
82
104
  window.location.href = result.data.sessionUrl;
@@ -13,7 +13,7 @@ import { UserState } from './money-price-types.mjs';
13
13
 
14
14
  function MoneyPriceInteractive({ data, config, upgradeApiEndpoint, signInPath }) {
15
15
  const fingerprintContext = useFingerprintContextSafe();
16
- const { redirectToSignIn } = useClerk();
16
+ const { redirectToSignIn, user } = useClerk();
17
17
  const router = useRouter();
18
18
  const [billingType, setBillingType] = useState(data.billingSwitch.defaultKey);
19
19
  const [isProcessing, setIsProcessing] = useState(false);
@@ -36,14 +36,17 @@ function MoneyPriceInteractive({ data, config, upgradeApiEndpoint, signInPath })
36
36
  }, [fingerprintContext]);
37
37
  // 优化 userContext 使用 useMemo
38
38
  const userContext = useMemo(() => {
39
- var _a, _b, _c, _d;
40
- return ({
41
- isAuthenticated: !!((_a = fingerprintContext === null || fingerprintContext === void 0 ? void 0 : fingerprintContext.xUser) === null || _a === void 0 ? void 0 : _a.clerkUserId),
42
- subscriptionStatus: getUserState(),
43
- subscriptionType: ((_c = (_b = fingerprintContext === null || fingerprintContext === void 0 ? void 0 : fingerprintContext.xSubscription) === null || _b === void 0 ? void 0 : _b.priceId) === null || _c === void 0 ? void 0 : _c.includes('yearly')) ? 'yearly' : 'monthly',
44
- subscriptionEndDate: (_d = fingerprintContext === null || fingerprintContext === void 0 ? void 0 : fingerprintContext.xSubscription) === null || _d === void 0 ? void 0 : _d.subPeriodEnd
45
- });
46
- }, [fingerprintContext, getUserState]);
39
+ var _a, _b, _c;
40
+ // 使用 Clerk 的 user 对象判断登录状态
41
+ const isAuth = !!(user === null || user === void 0 ? void 0 : user.id);
42
+ const userState = getUserState();
43
+ return {
44
+ isAuthenticated: isAuth,
45
+ subscriptionStatus: isAuth ? userState : UserState.Anonymous,
46
+ subscriptionType: ((_b = (_a = fingerprintContext === null || fingerprintContext === void 0 ? void 0 : fingerprintContext.xSubscription) === null || _a === void 0 ? void 0 : _a.priceId) === null || _b === void 0 ? void 0 : _b.includes('yearly')) ? 'yearly' : 'monthly',
47
+ subscriptionEndDate: (_c = fingerprintContext === null || fingerprintContext === void 0 ? void 0 : fingerprintContext.xSubscription) === null || _c === void 0 ? void 0 : _c.subPeriodEnd
48
+ };
49
+ }, [user, fingerprintContext, getUserState]);
47
50
  // 处理登录
48
51
  const handleLogin = useCallback(() => {
49
52
  if (signInPath) {
@@ -75,6 +78,25 @@ function MoneyPriceInteractive({ data, config, upgradeApiEndpoint, signInPath })
75
78
  provider: config.activeProvider
76
79
  })
77
80
  });
81
+ // 检查是否是重定向或非JSON响应
82
+ if (response.redirected || response.status === 302 || response.status === 301) {
83
+ // 如果是重定向,直接跳转到重定向URL(通常是登录页面)
84
+ window.location.href = response.url;
85
+ return;
86
+ }
87
+ // 检查Content-Type是否为JSON
88
+ const contentType = response.headers.get('content-type');
89
+ if (!contentType || !contentType.includes('application/json')) {
90
+ // 如果不是JSON响应,可能是HTML登录页面,提示用户重新登录
91
+ console.error('Received non-JSON response, user may need to login');
92
+ if (signInPath) {
93
+ window.location.href = signInPath;
94
+ }
95
+ else {
96
+ redirectToSignIn();
97
+ }
98
+ return;
99
+ }
78
100
  const result = yield response.json();
79
101
  if (result.success && ((_a = result.data) === null || _a === void 0 ? void 0 : _a.sessionUrl)) {
80
102
  window.location.href = result.data.sessionUrl;
@@ -1,6 +1,6 @@
1
1
  'use strict';
2
2
 
3
- var coseBase$1 = require('../../../../../_virtual/cose-base2.js');
3
+ var coseBase$1 = require('../../../../../_virtual/cose-base.js');
4
4
  var layoutBase = require('../../../layout-base@1.0.2/node_modules/layout-base/layout-base.js');
5
5
 
6
6
  var coseBase = coseBase$1.__module.exports;
@@ -1,6 +1,6 @@
1
1
  'use strict';
2
2
 
3
- var coseBase$1 = require('../../../../../_virtual/cose-base.js');
3
+ var coseBase$1 = require('../../../../../_virtual/cose-base2.js');
4
4
  var layoutBase = require('../../../layout-base@2.0.1/node_modules/layout-base/layout-base.js');
5
5
 
6
6
  var coseBase = coseBase$1.__module.exports;
@@ -1,6 +1,6 @@
1
1
  'use strict';
2
2
 
3
- var layoutBase$1 = require('../../../../../_virtual/layout-base2.js');
3
+ var layoutBase$1 = require('../../../../../_virtual/layout-base.js');
4
4
 
5
5
  var layoutBase = layoutBase$1.__module.exports;
6
6
 
@@ -1,6 +1,6 @@
1
1
  'use strict';
2
2
 
3
- var layoutBase$1 = require('../../../../../_virtual/layout-base.js');
3
+ var layoutBase$1 = require('../../../../../_virtual/layout-base2.js');
4
4
 
5
5
  var layoutBase = layoutBase$1.__module.exports;
6
6
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@windrun-huaiin/third-ui",
3
- "version": "7.4.0",
3
+ "version": "7.4.1",
4
4
  "description": "Third-party integrated UI components for windrun-huaiin projects",
5
5
  "main": "./dist/index.js",
6
6
  "module": "./dist/index.mjs",
@@ -75,8 +75,8 @@
75
75
  "mermaid": "^11.6.0",
76
76
  "react-medium-image-zoom": "^5.2.14",
77
77
  "zod": "^3.22.4",
78
- "@windrun-huaiin/lib": "^7.1.2",
79
- "@windrun-huaiin/base-ui": "^8.1.2"
78
+ "@windrun-huaiin/base-ui": "^8.1.2",
79
+ "@windrun-huaiin/lib": "^7.1.2"
80
80
  },
81
81
  "peerDependencies": {
82
82
  "react": "19.1.0",
@@ -21,7 +21,7 @@ export function MoneyPriceInteractive({
21
21
  signInPath
22
22
  }: MoneyPriceInteractiveProps) {
23
23
  const fingerprintContext = useFingerprintContextSafe();
24
- const { redirectToSignIn } = useClerk();
24
+ const { redirectToSignIn, user } = useClerk();
25
25
  const router = useRouter();
26
26
  const [billingType, setBillingType] = useState<'monthly' | 'yearly'>(
27
27
  data.billingSwitch.defaultKey as 'monthly' | 'yearly'
@@ -47,12 +47,18 @@ export function MoneyPriceInteractive({
47
47
  }, [fingerprintContext]);
48
48
 
49
49
  // 优化 userContext 使用 useMemo
50
- const userContext = useMemo<UserContext>(() => ({
51
- isAuthenticated: !!fingerprintContext?.xUser?.clerkUserId,
52
- subscriptionStatus: getUserState(),
53
- subscriptionType: fingerprintContext?.xSubscription?.priceId?.includes('yearly') ? 'yearly' : 'monthly',
54
- subscriptionEndDate: fingerprintContext?.xSubscription?.subPeriodEnd
55
- }), [fingerprintContext, getUserState]);
50
+ const userContext = useMemo<UserContext>(() => {
51
+ // 使用 Clerk 的 user 对象判断登录状态
52
+ const isAuth = !!user?.id;
53
+ const userState = getUserState();
54
+
55
+ return {
56
+ isAuthenticated: isAuth,
57
+ subscriptionStatus: isAuth ? userState : UserState.Anonymous,
58
+ subscriptionType: fingerprintContext?.xSubscription?.priceId?.includes('yearly') ? 'yearly' : 'monthly',
59
+ subscriptionEndDate: fingerprintContext?.xSubscription?.subPeriodEnd
60
+ };
61
+ }, [user, fingerprintContext, getUserState]);
56
62
 
57
63
  // 处理登录
58
64
  const handleLogin = useCallback(() => {
@@ -92,6 +98,26 @@ export function MoneyPriceInteractive({
92
98
  })
93
99
  });
94
100
 
101
+ // 检查是否是重定向或非JSON响应
102
+ if (response.redirected || response.status === 302 || response.status === 301) {
103
+ // 如果是重定向,直接跳转到重定向URL(通常是登录页面)
104
+ window.location.href = response.url;
105
+ return;
106
+ }
107
+
108
+ // 检查Content-Type是否为JSON
109
+ const contentType = response.headers.get('content-type');
110
+ if (!contentType || !contentType.includes('application/json')) {
111
+ // 如果不是JSON响应,可能是HTML登录页面,提示用户重新登录
112
+ console.error('Received non-JSON response, user may need to login');
113
+ if (signInPath) {
114
+ window.location.href = signInPath;
115
+ } else {
116
+ redirectToSignIn();
117
+ }
118
+ return;
119
+ }
120
+
95
121
  const result = await response.json();
96
122
 
97
123
  if (result.success && result.data?.sessionUrl) {