@windrun-huaiin/third-ui 14.0.3 → 14.1.0
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/clerk/fingerprint/fingerprint-provider.js +150 -26
- package/dist/clerk/fingerprint/fingerprint-provider.mjs +151 -27
- package/dist/clerk/fingerprint/types.d.ts +1 -0
- package/dist/clerk/fingerprint/use-fingerprint.js +20 -1
- package/dist/clerk/fingerprint/use-fingerprint.mjs +21 -2
- package/package.json +1 -1
- package/src/clerk/fingerprint/fingerprint-provider.tsx +349 -87
- package/src/clerk/fingerprint/types.ts +2 -1
- package/src/clerk/fingerprint/use-fingerprint.ts +23 -2
|
@@ -61,6 +61,7 @@ export interface UseFingerprintResult {
|
|
|
61
61
|
isLoading: boolean;
|
|
62
62
|
isInitialized: boolean;
|
|
63
63
|
error: string | null;
|
|
64
|
+
clearError: () => void;
|
|
64
65
|
initializeAnonymousUser: () => Promise<void>;
|
|
65
66
|
refreshUserData: () => Promise<void>;
|
|
66
67
|
}
|
|
@@ -74,4 +75,4 @@ export interface FingerprintProviderProps {
|
|
|
74
75
|
// Fetch wrapper type
|
|
75
76
|
export interface FingerprintFetch {
|
|
76
77
|
(url: string | URL | Request, init?: RequestInit): Promise<Response>;
|
|
77
|
-
}
|
|
78
|
+
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
'use client';
|
|
2
2
|
|
|
3
|
-
import { useCallback, useEffect, useState } from 'react';
|
|
3
|
+
import { useCallback, useEffect, useRef, useState } from 'react';
|
|
4
4
|
import {
|
|
5
5
|
createFingerprintHeaders,
|
|
6
6
|
getOrCreateFirstTouchData,
|
|
@@ -30,6 +30,7 @@ export function useFingerprint(config: FingerprintConfig): UseFingerprintResult
|
|
|
30
30
|
isLoading: false,
|
|
31
31
|
isInitialized: false,
|
|
32
32
|
error: 'Server-side rendering is not supported',
|
|
33
|
+
clearError: () => {},
|
|
33
34
|
initializeAnonymousUser: async () => {},
|
|
34
35
|
refreshUserData: async () => {},
|
|
35
36
|
};
|
|
@@ -42,6 +43,11 @@ export function useFingerprint(config: FingerprintConfig): UseFingerprintResult
|
|
|
42
43
|
const [isLoading, setIsLoading] = useState(true);
|
|
43
44
|
const [isInitialized, setIsInitialized] = useState(false);
|
|
44
45
|
const [error, setError] = useState<string | null>(null);
|
|
46
|
+
const isInitializingAnonymousUserRef = useRef(false);
|
|
47
|
+
const requestedAnonymousFingerprintRef = useRef<string | null>(null);
|
|
48
|
+
const clearError = useCallback(() => {
|
|
49
|
+
setError(null);
|
|
50
|
+
}, []);
|
|
45
51
|
|
|
46
52
|
/**
|
|
47
53
|
* 第一阶段:初始化fingerprint ID
|
|
@@ -71,7 +77,19 @@ export function useFingerprint(config: FingerprintConfig): UseFingerprintResult
|
|
|
71
77
|
return;
|
|
72
78
|
}
|
|
73
79
|
|
|
80
|
+
if (isInitializingAnonymousUserRef.current) {
|
|
81
|
+
console.log('Skipping anonymous user initialization because a request is already in flight:', fingerprintId);
|
|
82
|
+
return;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
if (requestedAnonymousFingerprintRef.current === fingerprintId && isInitialized) {
|
|
86
|
+
console.log('Skipping anonymous user initialization because fingerprint is already initialized:', fingerprintId);
|
|
87
|
+
return;
|
|
88
|
+
}
|
|
89
|
+
|
|
74
90
|
try {
|
|
91
|
+
isInitializingAnonymousUserRef.current = true;
|
|
92
|
+
requestedAnonymousFingerprintRef.current = fingerprintId;
|
|
75
93
|
setIsLoading(true);
|
|
76
94
|
setError(null);
|
|
77
95
|
|
|
@@ -110,12 +128,14 @@ export function useFingerprint(config: FingerprintConfig): UseFingerprintResult
|
|
|
110
128
|
throw new Error(data.error || 'Unknown error occurred');
|
|
111
129
|
}
|
|
112
130
|
} catch (err) {
|
|
131
|
+
requestedAnonymousFingerprintRef.current = null;
|
|
113
132
|
console.error('Failed to initialize anonymous user:', err);
|
|
114
133
|
setError(err instanceof Error ? err.message : 'Unknown error');
|
|
115
134
|
} finally {
|
|
135
|
+
isInitializingAnonymousUserRef.current = false;
|
|
116
136
|
setIsLoading(false);
|
|
117
137
|
}
|
|
118
|
-
}, [fingerprintId, config.apiEndpoint]);
|
|
138
|
+
}, [fingerprintId, config.apiEndpoint, isInitialized]);
|
|
119
139
|
|
|
120
140
|
/**
|
|
121
141
|
* 刷新用户数据 - 使用POST请求(后端支持upsert逻辑)
|
|
@@ -185,6 +205,7 @@ export function useFingerprint(config: FingerprintConfig): UseFingerprintResult
|
|
|
185
205
|
isLoading,
|
|
186
206
|
isInitialized,
|
|
187
207
|
error,
|
|
208
|
+
clearError,
|
|
188
209
|
initializeAnonymousUser,
|
|
189
210
|
refreshUserData,
|
|
190
211
|
};
|