@oxyhq/services 5.7.1 → 5.7.3
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/lib/commonjs/core/index.js +0 -57
- package/lib/commonjs/core/index.js.map +1 -1
- package/lib/commonjs/ui/context/OxyContext.js +9 -29
- package/lib/commonjs/ui/context/OxyContext.js.map +1 -1
- package/lib/commonjs/ui/hooks/useSessionSocket.js +1 -4
- package/lib/commonjs/ui/hooks/useSessionSocket.js.map +1 -1
- package/lib/module/core/index.js +0 -57
- package/lib/module/core/index.js.map +1 -1
- package/lib/module/ui/context/OxyContext.js +9 -29
- package/lib/module/ui/context/OxyContext.js.map +1 -1
- package/lib/module/ui/hooks/useSessionSocket.js +1 -4
- package/lib/module/ui/hooks/useSessionSocket.js.map +1 -1
- package/lib/typescript/core/index.d.ts +0 -6
- package/lib/typescript/core/index.d.ts.map +1 -1
- package/lib/typescript/ui/context/OxyContext.d.ts.map +1 -1
- package/lib/typescript/ui/hooks/useSessionSocket.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/core/index.ts +0 -60
- package/src/ui/context/OxyContext.tsx +9 -29
- package/src/ui/hooks/useSessionSocket.ts +1 -4
|
@@ -138,18 +138,6 @@ export const OxyContextProvider: React.FC<OxyContextProviderProps> = ({
|
|
|
138
138
|
// Add a new state to track token restoration
|
|
139
139
|
const [tokenReady, setTokenReady] = React.useState(false);
|
|
140
140
|
|
|
141
|
-
// Add refs to prevent duplicate API calls
|
|
142
|
-
const initAuthRef = React.useRef(false);
|
|
143
|
-
const tokenRestoreRef = React.useRef(false);
|
|
144
|
-
|
|
145
|
-
// Development warning about React StrictMode
|
|
146
|
-
React.useEffect(() => {
|
|
147
|
-
if (__DEV__) {
|
|
148
|
-
console.log('🔍 OxyContext: React StrictMode may cause effects to run twice in development');
|
|
149
|
-
console.log('🔍 This is normal and helps detect side effects. Production builds will not have this behavior.');
|
|
150
|
-
}
|
|
151
|
-
}, []);
|
|
152
|
-
|
|
153
141
|
// Storage keys (memoized to prevent infinite loops)
|
|
154
142
|
const keys = useMemo(() => getSecureStorageKeys(storageKeyPrefix), [storageKeyPrefix]);
|
|
155
143
|
|
|
@@ -171,12 +159,8 @@ export const OxyContextProvider: React.FC<OxyContextProviderProps> = ({
|
|
|
171
159
|
// Effect to initialize authentication state
|
|
172
160
|
useEffect(() => {
|
|
173
161
|
const initAuth = async () => {
|
|
174
|
-
if (!storage
|
|
175
|
-
|
|
176
|
-
// Prevent multiple simultaneous initializations
|
|
177
|
-
if (isLoading) return;
|
|
162
|
+
if (!storage) return;
|
|
178
163
|
|
|
179
|
-
initAuthRef.current = true;
|
|
180
164
|
useAuthStore.setState({ isLoading: true });
|
|
181
165
|
try {
|
|
182
166
|
// Load stored sessions
|
|
@@ -270,16 +254,15 @@ export const OxyContextProvider: React.FC<OxyContextProviderProps> = ({
|
|
|
270
254
|
}
|
|
271
255
|
};
|
|
272
256
|
|
|
273
|
-
if (storage
|
|
257
|
+
if (storage) {
|
|
274
258
|
initAuth();
|
|
275
259
|
}
|
|
276
|
-
}, [storage, oxyServices, keys
|
|
260
|
+
}, [storage, oxyServices, keys, onAuthStateChange]);
|
|
277
261
|
|
|
278
|
-
// Effect to restore token on app load or session switch
|
|
262
|
+
// Effect to restore token on app load or session switch
|
|
279
263
|
useEffect(() => {
|
|
280
264
|
const restoreToken = async () => {
|
|
281
|
-
if (activeSessionId && oxyServices
|
|
282
|
-
tokenRestoreRef.current = true;
|
|
265
|
+
if (activeSessionId && oxyServices) {
|
|
283
266
|
try {
|
|
284
267
|
await oxyServices.getTokenBySession(activeSessionId);
|
|
285
268
|
setTokenReady(true);
|
|
@@ -288,16 +271,13 @@ export const OxyContextProvider: React.FC<OxyContextProviderProps> = ({
|
|
|
288
271
|
await logout();
|
|
289
272
|
setTokenReady(false);
|
|
290
273
|
}
|
|
291
|
-
} else
|
|
274
|
+
} else {
|
|
292
275
|
setTokenReady(true); // No session, so token is not needed
|
|
293
276
|
}
|
|
294
277
|
};
|
|
295
|
-
|
|
296
|
-
// Only run
|
|
297
|
-
|
|
298
|
-
restoreToken();
|
|
299
|
-
}
|
|
300
|
-
}, [activeSessionId, oxyServices, tokenReady]); // Added tokenReady to prevent re-runs
|
|
278
|
+
restoreToken();
|
|
279
|
+
// Only run when activeSessionId or oxyServices changes
|
|
280
|
+
}, [activeSessionId, oxyServices]);
|
|
301
281
|
|
|
302
282
|
// Remove invalid session
|
|
303
283
|
const removeInvalidSession = useCallback(async (sessionId: string): Promise<void> => {
|
|
@@ -13,10 +13,9 @@ interface UseSessionSocketProps {
|
|
|
13
13
|
|
|
14
14
|
export function useSessionSocket({ userId, activeSessionId, refreshSessions, logout, baseURL, onRemoteSignOut }: UseSessionSocketProps) {
|
|
15
15
|
const socketRef = useRef<any>(null);
|
|
16
|
-
const connectedRef = useRef(false);
|
|
17
16
|
|
|
18
17
|
useEffect(() => {
|
|
19
|
-
if (!userId || !baseURL
|
|
18
|
+
if (!userId || !baseURL) return;
|
|
20
19
|
|
|
21
20
|
if (!socketRef.current) {
|
|
22
21
|
socketRef.current = io(baseURL, {
|
|
@@ -27,7 +26,6 @@ export function useSessionSocket({ userId, activeSessionId, refreshSessions, log
|
|
|
27
26
|
|
|
28
27
|
socket.on('connect', () => {
|
|
29
28
|
console.log('Socket connected:', socket.id);
|
|
30
|
-
connectedRef.current = true;
|
|
31
29
|
});
|
|
32
30
|
|
|
33
31
|
socket.emit('join', { userId: `user:${userId}` });
|
|
@@ -45,7 +43,6 @@ export function useSessionSocket({ userId, activeSessionId, refreshSessions, log
|
|
|
45
43
|
});
|
|
46
44
|
|
|
47
45
|
return () => {
|
|
48
|
-
connectedRef.current = false;
|
|
49
46
|
socket.emit('leave', { userId: `user:${userId}` });
|
|
50
47
|
socket.off('session_update');
|
|
51
48
|
};
|