@windrun-huaiin/third-ui 7.3.7 → 7.3.8

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.
@@ -57,7 +57,6 @@ function FingerprintStatus() {
57
57
  setIsOpen(false);
58
58
  }
59
59
  };
60
- // ESC键关闭弹框
61
60
  React.useEffect(() => {
62
61
  const handleEscKey = (e) => {
63
62
  if (e.key === 'Escape' && isOpen) {
@@ -71,6 +70,12 @@ function FingerprintStatus() {
71
70
  document.removeEventListener('keydown', handleEscKey);
72
71
  };
73
72
  }, [isOpen]);
73
+ // 确保 xUser 更新后才渲染内容
74
+ React.useEffect(() => {
75
+ if (xUser && !xUser.fingerprintId) {
76
+ console.warn('xUser.fingerprintId is missing:', xUser);
77
+ }
78
+ }, [xUser]);
74
79
  return (jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [jsxRuntime.jsx("button", { onClick: handleToggle, style: {
75
80
  position: 'fixed',
76
81
  top: '10px',
@@ -111,7 +116,7 @@ function FingerprintStatus() {
111
116
  zIndex: 9999,
112
117
  border: '1px solid #ccc',
113
118
  boxShadow: '0 4px 12px rgba(0, 0, 0, 0.2)',
114
- }, children: [jsxRuntime.jsx("h4", { style: { margin: '0 0 5px 0' }, children: "Fingerprint Debug" }), jsxRuntime.jsxs("div", { children: [jsxRuntime.jsx("strong", { children: "FP_ID:" }), " ", fingerprintId || 'None'] }), jsxRuntime.jsxs("div", { children: [jsxRuntime.jsx("strong", { children: "Loading:" }), " ", isLoading ? 'Yes' : 'No'] }), jsxRuntime.jsxs("div", { children: [jsxRuntime.jsx("strong", { children: "Initialized:" }), " ", isInitialized ? 'Yes' : 'No'] }), error && jsxRuntime.jsxs("div", { style: { color: 'red' }, children: [jsxRuntime.jsx("strong", { children: "Error:" }), " ", error] }), xUser && (jsxRuntime.jsxs("div", { children: [jsxRuntime.jsx("strong", { children: "user_id:" }), " ", xUser.userId, " ", jsxRuntime.jsx("br", {}), jsxRuntime.jsx("strong", { children: "clerk_user_id:" }), " ", xUser.clerkUserId || 'None', " ", jsxRuntime.jsx("br", {}), jsxRuntime.jsx("strong", { children: "email:" }), " ", xUser.email || 'None', " ", jsxRuntime.jsx("br", {})] })), xCredit && (jsxRuntime.jsxs("div", { children: [jsxRuntime.jsx("strong", { children: "Credits:" }), " ", xCredit.balanceFree, " Free + ", xCredit.balancePaid, " Paid = ", xCredit.totalBalance, " Total"] })), jsxRuntime.jsx("div", { children: xSubscription ? (jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [jsxRuntime.jsx("strong", { children: "user_id:" }), " ", xSubscription.userId, " ", jsxRuntime.jsx("br", {}), jsxRuntime.jsx("strong", { children: "pay_subscription_id:" }), " ", xSubscription.paySubscriptionId, " ", jsxRuntime.jsx("br", {}), jsxRuntime.jsx("strong", { children: "price_id:" }), " ", xSubscription.priceId || 'None', " ", jsxRuntime.jsx("br", {}), jsxRuntime.jsx("strong", { children: "price_name:" }), " ", xSubscription.priceName || 'None', " ", jsxRuntime.jsx("br", {}), jsxRuntime.jsx("strong", { children: "status:" }), " ", xSubscription.status || 'Free', " ", jsxRuntime.jsx("br", {}), jsxRuntime.jsx("strong", { children: "credits_allocated:" }), " ", xSubscription.creditsAllocated || '', " ", jsxRuntime.jsx("br", {}), jsxRuntime.jsx("strong", { children: "sub_period_start:" }), " ", xSubscription.subPeriodStart || '', " ", jsxRuntime.jsx("br", {}), jsxRuntime.jsx("strong", { children: "sub_period_end:" }), " ", xSubscription.subPeriodEnd || '', " ", jsxRuntime.jsx("br", {})] })) : (jsxRuntime.jsx("strong", { children: "No Subscription, Default as Hobby Plan" })) })] })] }))] }));
119
+ }, children: [jsxRuntime.jsx("h4", { style: { margin: '0 0 5px 0' }, children: "Fingerprint Debug" }), jsxRuntime.jsxs("div", { children: [jsxRuntime.jsx("strong", { children: "FP_ID:" }), " ", fingerprintId || 'None'] }), jsxRuntime.jsxs("div", { children: [jsxRuntime.jsx("strong", { children: "Loading:" }), " ", isLoading ? 'Yes' : 'No'] }), jsxRuntime.jsxs("div", { children: [jsxRuntime.jsx("strong", { children: "Initialized:" }), " ", isInitialized ? 'Yes' : 'No'] }), error && jsxRuntime.jsxs("div", { style: { color: 'red' }, children: [jsxRuntime.jsx("strong", { children: "Error:" }), " ", error] }), xUser && (jsxRuntime.jsxs("div", { children: [jsxRuntime.jsx("strong", { children: "user_id:" }), " ", xUser.userId || 'None', " ", jsxRuntime.jsx("br", {}), jsxRuntime.jsx("strong", { children: "fingerprintId:" }), " ", xUser.fingerprintId || 'None', " ", jsxRuntime.jsx("br", {}), jsxRuntime.jsx("strong", { children: "clerk_user_id:" }), " ", xUser.clerkUserId || 'None', " ", jsxRuntime.jsx("br", {}), jsxRuntime.jsx("strong", { children: "email:" }), " ", xUser.email || 'None', " ", jsxRuntime.jsx("br", {})] })), xCredit && (jsxRuntime.jsxs("div", { children: [jsxRuntime.jsx("strong", { children: "Credits:" }), " ", xCredit.balanceFree, " Free + ", xCredit.balancePaid, " Paid = ", xCredit.totalBalance, " Total"] })), jsxRuntime.jsx("div", { children: xSubscription ? (jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [jsxRuntime.jsx("strong", { children: "user_id:" }), " ", xSubscription.userId, " ", jsxRuntime.jsx("br", {}), jsxRuntime.jsx("strong", { children: "pay_subscription_id:" }), " ", xSubscription.paySubscriptionId || 'None', " ", jsxRuntime.jsx("br", {}), jsxRuntime.jsx("strong", { children: "price_id:" }), " ", xSubscription.priceId || 'None', " ", jsxRuntime.jsx("br", {}), jsxRuntime.jsx("strong", { children: "price_name:" }), " ", xSubscription.priceName || 'None', " ", jsxRuntime.jsx("br", {}), jsxRuntime.jsx("strong", { children: "status:" }), " ", xSubscription.status || 'Free', " ", jsxRuntime.jsx("br", {}), jsxRuntime.jsx("strong", { children: "credits_allocated:" }), " ", xSubscription.creditsAllocated || '', " ", jsxRuntime.jsx("br", {}), jsxRuntime.jsx("strong", { children: "sub_period_start:" }), " ", xSubscription.subPeriodStart || '', " ", jsxRuntime.jsx("br", {}), jsxRuntime.jsx("strong", { children: "sub_period_end:" }), " ", xSubscription.subPeriodEnd || '', " ", jsxRuntime.jsx("br", {})] })) : (jsxRuntime.jsx("strong", { children: "No Subscription, Default as Hobby Plan" })) })] })] }))] }));
115
120
  }
116
121
 
117
122
  exports.FingerprintProvider = FingerprintProvider;
@@ -55,7 +55,6 @@ function FingerprintStatus() {
55
55
  setIsOpen(false);
56
56
  }
57
57
  };
58
- // ESC键关闭弹框
59
58
  useEffect(() => {
60
59
  const handleEscKey = (e) => {
61
60
  if (e.key === 'Escape' && isOpen) {
@@ -69,6 +68,12 @@ function FingerprintStatus() {
69
68
  document.removeEventListener('keydown', handleEscKey);
70
69
  };
71
70
  }, [isOpen]);
71
+ // 确保 xUser 更新后才渲染内容
72
+ useEffect(() => {
73
+ if (xUser && !xUser.fingerprintId) {
74
+ console.warn('xUser.fingerprintId is missing:', xUser);
75
+ }
76
+ }, [xUser]);
72
77
  return (jsxs(Fragment, { children: [jsx("button", { onClick: handleToggle, style: {
73
78
  position: 'fixed',
74
79
  top: '10px',
@@ -109,7 +114,7 @@ function FingerprintStatus() {
109
114
  zIndex: 9999,
110
115
  border: '1px solid #ccc',
111
116
  boxShadow: '0 4px 12px rgba(0, 0, 0, 0.2)',
112
- }, children: [jsx("h4", { style: { margin: '0 0 5px 0' }, children: "Fingerprint Debug" }), jsxs("div", { children: [jsx("strong", { children: "FP_ID:" }), " ", fingerprintId || 'None'] }), jsxs("div", { children: [jsx("strong", { children: "Loading:" }), " ", isLoading ? 'Yes' : 'No'] }), jsxs("div", { children: [jsx("strong", { children: "Initialized:" }), " ", isInitialized ? 'Yes' : 'No'] }), error && jsxs("div", { style: { color: 'red' }, children: [jsx("strong", { children: "Error:" }), " ", error] }), xUser && (jsxs("div", { children: [jsx("strong", { children: "user_id:" }), " ", xUser.userId, " ", jsx("br", {}), jsx("strong", { children: "clerk_user_id:" }), " ", xUser.clerkUserId || 'None', " ", jsx("br", {}), jsx("strong", { children: "email:" }), " ", xUser.email || 'None', " ", jsx("br", {})] })), xCredit && (jsxs("div", { children: [jsx("strong", { children: "Credits:" }), " ", xCredit.balanceFree, " Free + ", xCredit.balancePaid, " Paid = ", xCredit.totalBalance, " Total"] })), jsx("div", { children: xSubscription ? (jsxs(Fragment, { children: [jsx("strong", { children: "user_id:" }), " ", xSubscription.userId, " ", jsx("br", {}), jsx("strong", { children: "pay_subscription_id:" }), " ", xSubscription.paySubscriptionId, " ", jsx("br", {}), jsx("strong", { children: "price_id:" }), " ", xSubscription.priceId || 'None', " ", jsx("br", {}), jsx("strong", { children: "price_name:" }), " ", xSubscription.priceName || 'None', " ", jsx("br", {}), jsx("strong", { children: "status:" }), " ", xSubscription.status || 'Free', " ", jsx("br", {}), jsx("strong", { children: "credits_allocated:" }), " ", xSubscription.creditsAllocated || '', " ", jsx("br", {}), jsx("strong", { children: "sub_period_start:" }), " ", xSubscription.subPeriodStart || '', " ", jsx("br", {}), jsx("strong", { children: "sub_period_end:" }), " ", xSubscription.subPeriodEnd || '', " ", jsx("br", {})] })) : (jsx("strong", { children: "No Subscription, Default as Hobby Plan" })) })] })] }))] }));
117
+ }, children: [jsx("h4", { style: { margin: '0 0 5px 0' }, children: "Fingerprint Debug" }), jsxs("div", { children: [jsx("strong", { children: "FP_ID:" }), " ", fingerprintId || 'None'] }), jsxs("div", { children: [jsx("strong", { children: "Loading:" }), " ", isLoading ? 'Yes' : 'No'] }), jsxs("div", { children: [jsx("strong", { children: "Initialized:" }), " ", isInitialized ? 'Yes' : 'No'] }), error && jsxs("div", { style: { color: 'red' }, children: [jsx("strong", { children: "Error:" }), " ", error] }), xUser && (jsxs("div", { children: [jsx("strong", { children: "user_id:" }), " ", xUser.userId || 'None', " ", jsx("br", {}), jsx("strong", { children: "fingerprintId:" }), " ", xUser.fingerprintId || 'None', " ", jsx("br", {}), jsx("strong", { children: "clerk_user_id:" }), " ", xUser.clerkUserId || 'None', " ", jsx("br", {}), jsx("strong", { children: "email:" }), " ", xUser.email || 'None', " ", jsx("br", {})] })), xCredit && (jsxs("div", { children: [jsx("strong", { children: "Credits:" }), " ", xCredit.balanceFree, " Free + ", xCredit.balancePaid, " Paid = ", xCredit.totalBalance, " Total"] })), jsx("div", { children: xSubscription ? (jsxs(Fragment, { children: [jsx("strong", { children: "user_id:" }), " ", xSubscription.userId, " ", jsx("br", {}), jsx("strong", { children: "pay_subscription_id:" }), " ", xSubscription.paySubscriptionId || 'None', " ", jsx("br", {}), jsx("strong", { children: "price_id:" }), " ", xSubscription.priceId || 'None', " ", jsx("br", {}), jsx("strong", { children: "price_name:" }), " ", xSubscription.priceName || 'None', " ", jsx("br", {}), jsx("strong", { children: "status:" }), " ", xSubscription.status || 'Free', " ", jsx("br", {}), jsx("strong", { children: "credits_allocated:" }), " ", xSubscription.creditsAllocated || '', " ", jsx("br", {}), jsx("strong", { children: "sub_period_start:" }), " ", xSubscription.subPeriodStart || '', " ", jsx("br", {}), jsx("strong", { children: "sub_period_end:" }), " ", xSubscription.subPeriodEnd || '', " ", jsx("br", {})] })) : (jsx("strong", { children: "No Subscription, Default as Hobby Plan" })) })] })] }))] }));
113
118
  }
114
119
 
115
120
  export { FingerprintProvider, FingerprintStatus, useFingerprintContext, useFingerprintContextSafe, withFingerprint };
@@ -1,4 +1,4 @@
1
- import type { UseFingerprintResult, FingerprintConfig } from './types';
1
+ import type { FingerprintConfig, UseFingerprintResult } from './types';
2
2
  /**
3
3
  * Hook for managing fingerprint ID and anonymous user data
4
4
  * Accepts configuration to customize API endpoint and behavior
@@ -51,40 +51,37 @@ function useFingerprint(config) {
51
51
  * 第二阶段:初始化匿名用户
52
52
  */
53
53
  const initializeAnonymousUser = React.useCallback(() => tslib_es6.__awaiter(this, void 0, void 0, function* () {
54
+ var _a;
54
55
  if (!fingerprintId) {
55
- console.warn('Cannot initialize user: Fingerprint ID is missing', {
56
- fingerprintId,
57
- isLoading,
58
- isInitialized,
59
- });
56
+ console.warn('Cannot initialize user: Fingerprint ID is missing', { fingerprintId, isLoading, isInitialized });
60
57
  setError('Cannot initialize user: Missing fingerprint ID');
61
58
  return;
62
59
  }
63
60
  try {
64
61
  setIsLoading(true);
65
62
  setError(null);
63
+ console.log('Initializing anonymous user with fingerprintId:', fingerprintId);
66
64
  const fingerprintHeaders = yield fingerprintClient.createFingerprintHeaders();
67
65
  const response = yield fetch(config.apiEndpoint, {
68
66
  method: 'POST',
69
67
  headers: Object.assign({ 'Content-Type': 'application/json' }, fingerprintHeaders),
70
- body: JSON.stringify({
71
- fingerprintId: fingerprintId,
72
- }),
68
+ body: JSON.stringify({ fingerprintId }),
73
69
  });
74
70
  if (!response.ok) {
75
71
  const errorData = yield response.json().catch(() => ({}));
76
72
  throw new Error(errorData.error || 'Failed to initialize anonymous user');
77
73
  }
78
74
  const data = yield response.json();
75
+ console.log('API response in initializeAnonymousUser:', data);
79
76
  if (data.success) {
80
- setXUser(data.xUser);
81
- setXCredit(data.xCredit);
82
- setXSubscription(data.xSubscription);
77
+ const updatedXUser = data.xUser || { userId: '', fingerprintId, clerkUserId: '', email: '', status: '', createdAt: '' };
78
+ console.log('Setting xUser:', updatedXUser);
79
+ setXUser(updatedXUser);
80
+ setXCredit(data.xCredit || null);
81
+ setXSubscription(data.xSubscription || null);
83
82
  setIsInitialized(true);
84
- // 确保fingerprint ID同步
85
- if (data.user.fingerprintId !== fingerprintId) {
86
- fingerprintClient.setFingerprintId(data.user.fingerprintId);
87
- setFingerprintIdState(data.user.fingerprintId);
83
+ if (((_a = data.xUser) === null || _a === void 0 ? void 0 : _a.fingerprintId) && data.xUser.fingerprintId !== fingerprintId) {
84
+ setFingerprintIdState(data.xUser.fingerprintId);
88
85
  }
89
86
  }
90
87
  else {
@@ -104,11 +101,7 @@ function useFingerprint(config) {
104
101
  */
105
102
  const refreshUserData = React.useCallback(() => tslib_es6.__awaiter(this, void 0, void 0, function* () {
106
103
  if (!fingerprintId) {
107
- console.warn('Cannot refresh user data: Fingerprint ID is missing', {
108
- fingerprintId,
109
- isLoading,
110
- isInitialized,
111
- });
104
+ console.warn('Cannot refresh user data: Fingerprint ID is missing', { fingerprintId, isLoading, isInitialized });
112
105
  setError('Cannot refresh user data: Missing fingerprint ID');
113
106
  return;
114
107
  }
@@ -129,9 +122,10 @@ function useFingerprint(config) {
129
122
  }
130
123
  const data = yield response.json();
131
124
  if (data.success) {
132
- setXUser(data.xUser);
133
- setXCredit(data.xCredit);
134
- setXSubscription(data.xSubscription);
125
+ const updatedXUser = data.xUser || { userId: '', fingerprintId, clerkUserId: '', email: '', status: '', createdAt: '' };
126
+ setXUser(updatedXUser);
127
+ setXCredit(data.xCredit || null);
128
+ setXSubscription(data.xSubscription || null);
135
129
  }
136
130
  }
137
131
  catch (err) {
@@ -144,11 +138,7 @@ function useFingerprint(config) {
144
138
  */
145
139
  const checkExistingUser = React.useCallback(() => tslib_es6.__awaiter(this, void 0, void 0, function* () {
146
140
  if (!fingerprintId) {
147
- console.warn('Cannot check existing user: Fingerprint ID is missing', {
148
- fingerprintId,
149
- isLoading,
150
- isInitialized,
151
- });
141
+ console.warn('Cannot check existing user: Fingerprint ID is missing', { fingerprintId, isLoading, isInitialized });
152
142
  return;
153
143
  }
154
144
  try {
@@ -160,9 +150,10 @@ function useFingerprint(config) {
160
150
  if (response.ok) {
161
151
  const data = yield response.json();
162
152
  if (data.success) {
163
- setXUser(data.xUser);
164
- setXCredit(data.xCredit);
165
- setXSubscription(data.xSubscription);
153
+ const updatedXUser = data.xUser || { userId: '', fingerprintId, clerkUserId: '', email: '', status: '', createdAt: '' };
154
+ setXUser(updatedXUser);
155
+ setXCredit(data.xCredit || null);
156
+ setXSubscription(data.xSubscription || null);
166
157
  setIsInitialized(true);
167
158
  }
168
159
  }
@@ -1,7 +1,7 @@
1
1
  "use client";
2
2
  import { __awaiter } from '../../node_modules/.pnpm/@rollup_plugin-typescript@12.1.4_rollup@4.46.2_tslib@2.8.1_typescript@5.9.2/node_modules/tslib/tslib.es6.mjs';
3
3
  import { useState, useCallback, useEffect } from 'react';
4
- import { createFingerprintHeaders, setFingerprintId, getOrGenerateFingerprintId } from './fingerprint-client.mjs';
4
+ import { createFingerprintHeaders, getOrGenerateFingerprintId } from './fingerprint-client.mjs';
5
5
 
6
6
  /**
7
7
  * Hook for managing fingerprint ID and anonymous user data
@@ -49,40 +49,37 @@ function useFingerprint(config) {
49
49
  * 第二阶段:初始化匿名用户
50
50
  */
51
51
  const initializeAnonymousUser = useCallback(() => __awaiter(this, void 0, void 0, function* () {
52
+ var _a;
52
53
  if (!fingerprintId) {
53
- console.warn('Cannot initialize user: Fingerprint ID is missing', {
54
- fingerprintId,
55
- isLoading,
56
- isInitialized,
57
- });
54
+ console.warn('Cannot initialize user: Fingerprint ID is missing', { fingerprintId, isLoading, isInitialized });
58
55
  setError('Cannot initialize user: Missing fingerprint ID');
59
56
  return;
60
57
  }
61
58
  try {
62
59
  setIsLoading(true);
63
60
  setError(null);
61
+ console.log('Initializing anonymous user with fingerprintId:', fingerprintId);
64
62
  const fingerprintHeaders = yield createFingerprintHeaders();
65
63
  const response = yield fetch(config.apiEndpoint, {
66
64
  method: 'POST',
67
65
  headers: Object.assign({ 'Content-Type': 'application/json' }, fingerprintHeaders),
68
- body: JSON.stringify({
69
- fingerprintId: fingerprintId,
70
- }),
66
+ body: JSON.stringify({ fingerprintId }),
71
67
  });
72
68
  if (!response.ok) {
73
69
  const errorData = yield response.json().catch(() => ({}));
74
70
  throw new Error(errorData.error || 'Failed to initialize anonymous user');
75
71
  }
76
72
  const data = yield response.json();
73
+ console.log('API response in initializeAnonymousUser:', data);
77
74
  if (data.success) {
78
- setXUser(data.xUser);
79
- setXCredit(data.xCredit);
80
- setXSubscription(data.xSubscription);
75
+ const updatedXUser = data.xUser || { userId: '', fingerprintId, clerkUserId: '', email: '', status: '', createdAt: '' };
76
+ console.log('Setting xUser:', updatedXUser);
77
+ setXUser(updatedXUser);
78
+ setXCredit(data.xCredit || null);
79
+ setXSubscription(data.xSubscription || null);
81
80
  setIsInitialized(true);
82
- // 确保fingerprint ID同步
83
- if (data.user.fingerprintId !== fingerprintId) {
84
- setFingerprintId(data.user.fingerprintId);
85
- setFingerprintIdState(data.user.fingerprintId);
81
+ if (((_a = data.xUser) === null || _a === void 0 ? void 0 : _a.fingerprintId) && data.xUser.fingerprintId !== fingerprintId) {
82
+ setFingerprintIdState(data.xUser.fingerprintId);
86
83
  }
87
84
  }
88
85
  else {
@@ -102,11 +99,7 @@ function useFingerprint(config) {
102
99
  */
103
100
  const refreshUserData = useCallback(() => __awaiter(this, void 0, void 0, function* () {
104
101
  if (!fingerprintId) {
105
- console.warn('Cannot refresh user data: Fingerprint ID is missing', {
106
- fingerprintId,
107
- isLoading,
108
- isInitialized,
109
- });
102
+ console.warn('Cannot refresh user data: Fingerprint ID is missing', { fingerprintId, isLoading, isInitialized });
110
103
  setError('Cannot refresh user data: Missing fingerprint ID');
111
104
  return;
112
105
  }
@@ -127,9 +120,10 @@ function useFingerprint(config) {
127
120
  }
128
121
  const data = yield response.json();
129
122
  if (data.success) {
130
- setXUser(data.xUser);
131
- setXCredit(data.xCredit);
132
- setXSubscription(data.xSubscription);
123
+ const updatedXUser = data.xUser || { userId: '', fingerprintId, clerkUserId: '', email: '', status: '', createdAt: '' };
124
+ setXUser(updatedXUser);
125
+ setXCredit(data.xCredit || null);
126
+ setXSubscription(data.xSubscription || null);
133
127
  }
134
128
  }
135
129
  catch (err) {
@@ -142,11 +136,7 @@ function useFingerprint(config) {
142
136
  */
143
137
  const checkExistingUser = useCallback(() => __awaiter(this, void 0, void 0, function* () {
144
138
  if (!fingerprintId) {
145
- console.warn('Cannot check existing user: Fingerprint ID is missing', {
146
- fingerprintId,
147
- isLoading,
148
- isInitialized,
149
- });
139
+ console.warn('Cannot check existing user: Fingerprint ID is missing', { fingerprintId, isLoading, isInitialized });
150
140
  return;
151
141
  }
152
142
  try {
@@ -158,9 +148,10 @@ function useFingerprint(config) {
158
148
  if (response.ok) {
159
149
  const data = yield response.json();
160
150
  if (data.success) {
161
- setXUser(data.xUser);
162
- setXCredit(data.xCredit);
163
- setXSubscription(data.xSubscription);
151
+ const updatedXUser = data.xUser || { userId: '', fingerprintId, clerkUserId: '', email: '', status: '', createdAt: '' };
152
+ setXUser(updatedXUser);
153
+ setXCredit(data.xCredit || null);
154
+ setXSubscription(data.xSubscription || null);
164
155
  setIsInitialized(true);
165
156
  }
166
157
  }
@@ -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@1.0.2/node_modules/layout-base/layout-base.js');
5
5
 
6
6
  var coseBase = coseBase$1.__module.exports;
@@ -1,4 +1,4 @@
1
- import { __module as coseBase$1 } from '../../../../../_virtual/cose-base2.mjs';
1
+ import { __module as coseBase$1 } from '../../../../../_virtual/cose-base.mjs';
2
2
  import { __require as requireLayoutBase } from '../../../layout-base@1.0.2/node_modules/layout-base/layout-base.mjs';
3
3
 
4
4
  var coseBase = coseBase$1.exports;
@@ -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@2.0.1/node_modules/layout-base/layout-base.js');
5
5
 
6
6
  var coseBase = coseBase$1.__module.exports;
@@ -1,4 +1,4 @@
1
- import { __module as coseBase$1 } from '../../../../../_virtual/cose-base.mjs';
1
+ import { __module as coseBase$1 } from '../../../../../_virtual/cose-base2.mjs';
2
2
  import { __require as requireLayoutBase } from '../../../layout-base@2.0.1/node_modules/layout-base/layout-base.mjs';
3
3
 
4
4
  var coseBase = coseBase$1.exports;
@@ -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
 
@@ -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
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@windrun-huaiin/third-ui",
3
- "version": "7.3.7",
3
+ "version": "7.3.8",
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/base-ui": "^8.1.2",
79
- "@windrun-huaiin/lib": "^7.1.2"
78
+ "@windrun-huaiin/lib": "^7.1.2",
79
+ "@windrun-huaiin/base-ui": "^8.1.2"
80
80
  },
81
81
  "peerDependencies": {
82
82
  "react": "19.1.0",
@@ -91,7 +91,6 @@ export function FingerprintStatus() {
91
91
  }
92
92
  };
93
93
 
94
- // ESC键关闭弹框
95
94
  useEffect(() => {
96
95
  const handleEscKey = (e: KeyboardEvent) => {
97
96
  if (e.key === 'Escape' && isOpen) {
@@ -108,6 +107,13 @@ export function FingerprintStatus() {
108
107
  };
109
108
  }, [isOpen]);
110
109
 
110
+ // 确保 xUser 更新后才渲染内容
111
+ useEffect(() => {
112
+ if (xUser && !xUser.fingerprintId) {
113
+ console.warn('xUser.fingerprintId is missing:', xUser);
114
+ }
115
+ }, [xUser]);
116
+
111
117
  return (
112
118
  <>
113
119
  <button
@@ -177,7 +183,8 @@ export function FingerprintStatus() {
177
183
  {error && <div style={{ color: 'red' }}><strong>Error:</strong> {error}</div>}
178
184
  {xUser && (
179
185
  <div>
180
- <strong>user_id:</strong> {xUser.userId} <br/>
186
+ <strong>user_id:</strong> {xUser.userId || 'None'} <br/>
187
+ <strong>fingerprintId:</strong> {xUser.fingerprintId || 'None'} <br/>
181
188
  <strong>clerk_user_id:</strong> {xUser.clerkUserId || 'None'} <br/>
182
189
  <strong>email:</strong> {xUser.email || 'None'} <br/>
183
190
  </div>
@@ -191,7 +198,7 @@ export function FingerprintStatus() {
191
198
  {xSubscription ? (
192
199
  <>
193
200
  <strong>user_id:</strong> {xSubscription.userId} <br/>
194
- <strong>pay_subscription_id:</strong> {xSubscription.paySubscriptionId} <br/>
201
+ <strong>pay_subscription_id:</strong> {xSubscription.paySubscriptionId || 'None'} <br/>
195
202
  <strong>price_id:</strong> {xSubscription.priceId || 'None'} <br/>
196
203
  <strong>price_name:</strong> {xSubscription.priceName || 'None'} <br/>
197
204
  <strong>status:</strong> {xSubscription.status || 'Free'} <br/>
@@ -1,17 +1,16 @@
1
1
  'use client';
2
2
 
3
- import { useState, useEffect, useCallback } from 'react';
4
- import {
5
- getOrGenerateFingerprintId,
6
- setFingerprintId,
7
- createFingerprintHeaders
3
+ import { useCallback, useEffect, useState } from 'react';
4
+ import {
5
+ createFingerprintHeaders,
6
+ getOrGenerateFingerprintId
8
7
  } from './fingerprint-client';
9
- import type {
10
- XUser,
11
- XCredit,
8
+ import type {
9
+ FingerprintConfig,
10
+ UseFingerprintResult,
11
+ XCredit,
12
12
  XSubscription,
13
- UseFingerprintResult,
14
- FingerprintConfig
13
+ XUser
15
14
  } from './types';
16
15
 
17
16
  /**
@@ -63,11 +62,7 @@ export function useFingerprint(config: FingerprintConfig): UseFingerprintResult
63
62
  */
64
63
  const initializeAnonymousUser = useCallback(async () => {
65
64
  if (!fingerprintId) {
66
- console.warn('Cannot initialize user: Fingerprint ID is missing', {
67
- fingerprintId,
68
- isLoading,
69
- isInitialized,
70
- });
65
+ console.warn('Cannot initialize user: Fingerprint ID is missing', { fingerprintId, isLoading, isInitialized });
71
66
  setError('Cannot initialize user: Missing fingerprint ID');
72
67
  return;
73
68
  }
@@ -76,6 +71,7 @@ export function useFingerprint(config: FingerprintConfig): UseFingerprintResult
76
71
  setIsLoading(true);
77
72
  setError(null);
78
73
 
74
+ console.log('Initializing anonymous user with fingerprintId:', fingerprintId);
79
75
  const fingerprintHeaders = await createFingerprintHeaders();
80
76
  const response = await fetch(config.apiEndpoint, {
81
77
  method: 'POST',
@@ -83,9 +79,7 @@ export function useFingerprint(config: FingerprintConfig): UseFingerprintResult
83
79
  'Content-Type': 'application/json',
84
80
  ...fingerprintHeaders,
85
81
  },
86
- body: JSON.stringify({
87
- fingerprintId: fingerprintId,
88
- }),
82
+ body: JSON.stringify({ fingerprintId }),
89
83
  });
90
84
 
91
85
  if (!response.ok) {
@@ -94,17 +88,18 @@ export function useFingerprint(config: FingerprintConfig): UseFingerprintResult
94
88
  }
95
89
 
96
90
  const data = await response.json();
97
-
91
+ console.log('API response in initializeAnonymousUser:', data);
92
+
98
93
  if (data.success) {
99
- setXUser(data.xUser);
100
- setXCredit(data.xCredit);
101
- setXSubscription(data.xSubscription);
94
+ const updatedXUser = data.xUser || { userId: '', fingerprintId, clerkUserId: '', email: '', status: '', createdAt: '' };
95
+ console.log('Setting xUser:', updatedXUser);
96
+ setXUser(updatedXUser);
97
+ setXCredit(data.xCredit || null);
98
+ setXSubscription(data.xSubscription || null);
102
99
  setIsInitialized(true);
103
-
104
- // 确保fingerprint ID同步
105
- if (data.user.fingerprintId !== fingerprintId) {
106
- setFingerprintId(data.user.fingerprintId);
107
- setFingerprintIdState(data.user.fingerprintId);
100
+
101
+ if (data.xUser?.fingerprintId && data.xUser.fingerprintId !== fingerprintId) {
102
+ setFingerprintIdState(data.xUser.fingerprintId);
108
103
  }
109
104
  } else {
110
105
  throw new Error(data.error || 'Unknown error occurred');
@@ -122,11 +117,7 @@ export function useFingerprint(config: FingerprintConfig): UseFingerprintResult
122
117
  */
123
118
  const refreshUserData = useCallback(async () => {
124
119
  if (!fingerprintId) {
125
- console.warn('Cannot refresh user data: Fingerprint ID is missing', {
126
- fingerprintId,
127
- isLoading,
128
- isInitialized,
129
- });
120
+ console.warn('Cannot refresh user data: Fingerprint ID is missing', { fingerprintId, isLoading, isInitialized });
130
121
  setError('Cannot refresh user data: Missing fingerprint ID');
131
122
  return;
132
123
  }
@@ -150,11 +141,11 @@ export function useFingerprint(config: FingerprintConfig): UseFingerprintResult
150
141
  }
151
142
 
152
143
  const data = await response.json();
153
-
154
144
  if (data.success) {
155
- setXUser(data.xUser);
156
- setXCredit(data.xCredit);
157
- setXSubscription(data.xSubscription);
145
+ const updatedXUser = data.xUser || { userId: '', fingerprintId, clerkUserId: '', email: '', status: '', createdAt: '' };
146
+ setXUser(updatedXUser);
147
+ setXCredit(data.xCredit || null);
148
+ setXSubscription(data.xSubscription || null);
158
149
  }
159
150
  } catch (err) {
160
151
  console.error('Failed to refresh user data:', err);
@@ -167,11 +158,7 @@ export function useFingerprint(config: FingerprintConfig): UseFingerprintResult
167
158
  */
168
159
  const checkExistingUser = useCallback(async () => {
169
160
  if (!fingerprintId) {
170
- console.warn('Cannot check existing user: Fingerprint ID is missing', {
171
- fingerprintId,
172
- isLoading,
173
- isInitialized,
174
- });
161
+ console.warn('Cannot check existing user: Fingerprint ID is missing', { fingerprintId, isLoading, isInitialized });
175
162
  return;
176
163
  }
177
164
 
@@ -185,9 +172,10 @@ export function useFingerprint(config: FingerprintConfig): UseFingerprintResult
185
172
  if (response.ok) {
186
173
  const data = await response.json();
187
174
  if (data.success) {
188
- setXUser(data.xUser);
189
- setXCredit(data.xCredit);
190
- setXSubscription(data.xSubscription);
175
+ const updatedXUser = data.xUser || { userId: '', fingerprintId, clerkUserId: '', email: '', status: '', createdAt: '' };
176
+ setXUser(updatedXUser);
177
+ setXCredit(data.xCredit || null);
178
+ setXSubscription(data.xSubscription || null);
191
179
  setIsInitialized(true);
192
180
  }
193
181
  }
@@ -214,14 +202,12 @@ export function useFingerprint(config: FingerprintConfig): UseFingerprintResult
214
202
  // 第二阶段:有指纹ID后检查现有用户
215
203
  useEffect(() => {
216
204
  if (!fingerprintId || isInitialized || isLoading) return;
217
-
218
205
  checkExistingUser();
219
206
  }, [fingerprintId, isInitialized, isLoading, checkExistingUser]);
220
207
 
221
208
  // 第三阶段:如果没有现有用户且自动初始化开启,则创建新用户
222
209
  useEffect(() => {
223
210
  if (!fingerprintId || isInitialized || isLoading || error || config.autoInitialize === false) return;
224
-
225
211
  initializeAnonymousUser();
226
212
  }, [fingerprintId, isInitialized, isLoading, error, initializeAnonymousUser, config.autoInitialize]);
227
213