@pubflow/react 0.1.1 → 0.2.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.
- package/dist/index.cjs +65 -42
- package/dist/index.cjs.map +1 -1
- package/dist/index.esm.js +65 -42
- package/dist/index.esm.js.map +1 -1
- package/package.json +7 -7
package/dist/index.cjs
CHANGED
|
@@ -238,7 +238,7 @@ function PubflowProvider({ children, config, instances, defaultInstance = 'defau
|
|
|
238
238
|
};
|
|
239
239
|
}
|
|
240
240
|
}
|
|
241
|
-
}, [enableDebugTools
|
|
241
|
+
}, [enableDebugTools]); // ✅ OPTIMIZED: Only enableDebugTools as dependency
|
|
242
242
|
// Handle session expiration
|
|
243
243
|
const handleSessionExpired = React.useCallback(() => {
|
|
244
244
|
if (showSessionAlerts) {
|
|
@@ -258,6 +258,7 @@ function PubflowProvider({ children, config, instances, defaultInstance = 'defau
|
|
|
258
258
|
}
|
|
259
259
|
}, [onSessionRefreshed, showSessionAlerts]);
|
|
260
260
|
React.useEffect(() => {
|
|
261
|
+
let isMounted = true;
|
|
261
262
|
const initialize = async () => {
|
|
262
263
|
var _a, _b;
|
|
263
264
|
try {
|
|
@@ -266,6 +267,8 @@ function PubflowProvider({ children, config, instances, defaultInstance = 'defau
|
|
|
266
267
|
if (instances && instances.length > 0) {
|
|
267
268
|
// Initialize multiple instances
|
|
268
269
|
for (const instanceConfig of instances) {
|
|
270
|
+
if (!isMounted)
|
|
271
|
+
return; // Prevent state updates if unmounted
|
|
269
272
|
// Initialize configuration
|
|
270
273
|
const fullConfig = core.initConfig({
|
|
271
274
|
...instanceConfig,
|
|
@@ -283,34 +286,39 @@ function PubflowProvider({ children, config, instances, defaultInstance = 'defau
|
|
|
283
286
|
const apiClient = new core.ApiClient(fullConfig, storage);
|
|
284
287
|
// Create auth service
|
|
285
288
|
const authService = new core.AuthService(apiClient, storage, fullConfig);
|
|
286
|
-
// Get current user
|
|
289
|
+
// Get current user (optimized - no await in initialization)
|
|
287
290
|
let user = null;
|
|
288
291
|
let isAuthenticated = false;
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
292
|
+
// Don't block initialization with API calls
|
|
293
|
+
authService.getCurrentUser().then(currentUser => {
|
|
294
|
+
if (isMounted && currentUser) {
|
|
295
|
+
setContextValue(prev => ({
|
|
296
|
+
...prev,
|
|
297
|
+
instances: {
|
|
298
|
+
...prev.instances,
|
|
299
|
+
[instanceConfig.id]: {
|
|
300
|
+
...prev.instances[instanceConfig.id],
|
|
301
|
+
user: currentUser,
|
|
302
|
+
isAuthenticated: true,
|
|
303
|
+
isLoading: false
|
|
304
|
+
}
|
|
305
|
+
}
|
|
306
|
+
}));
|
|
307
|
+
}
|
|
308
|
+
}).catch(error => {
|
|
294
309
|
console.error(`Error getting current user for instance ${instanceConfig.id}:`, error);
|
|
295
|
-
}
|
|
296
|
-
// Create instance
|
|
297
|
-
|
|
298
|
-
config: fullConfig,
|
|
299
|
-
apiClient,
|
|
300
|
-
authService,
|
|
301
|
-
user,
|
|
302
|
-
isAuthenticated,
|
|
303
|
-
isLoading: false,
|
|
310
|
+
});
|
|
311
|
+
// Create instance with optimized functions
|
|
312
|
+
const createInstanceFunctions = (id) => ({
|
|
304
313
|
login: async (credentials) => {
|
|
305
314
|
const result = await authService.login(credentials);
|
|
306
|
-
if (result.success && result.user) {
|
|
307
|
-
// Update instance
|
|
315
|
+
if (result.success && result.user && isMounted) {
|
|
308
316
|
setContextValue(prev => ({
|
|
309
317
|
...prev,
|
|
310
318
|
instances: {
|
|
311
319
|
...prev.instances,
|
|
312
|
-
[
|
|
313
|
-
...prev.instances[
|
|
320
|
+
[id]: {
|
|
321
|
+
...prev.instances[id],
|
|
314
322
|
user: result.user,
|
|
315
323
|
isAuthenticated: true
|
|
316
324
|
}
|
|
@@ -321,35 +329,46 @@ function PubflowProvider({ children, config, instances, defaultInstance = 'defau
|
|
|
321
329
|
},
|
|
322
330
|
logout: async () => {
|
|
323
331
|
await authService.logout();
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
332
|
+
if (isMounted) {
|
|
333
|
+
setContextValue(prev => ({
|
|
334
|
+
...prev,
|
|
335
|
+
instances: {
|
|
336
|
+
...prev.instances,
|
|
337
|
+
[id]: {
|
|
338
|
+
...prev.instances[id],
|
|
339
|
+
user: null,
|
|
340
|
+
isAuthenticated: false
|
|
341
|
+
}
|
|
333
342
|
}
|
|
334
|
-
}
|
|
335
|
-
}
|
|
343
|
+
}));
|
|
344
|
+
}
|
|
336
345
|
},
|
|
337
346
|
validateSession: async () => {
|
|
338
347
|
const result = await authService.validateSession();
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
+
if (isMounted) {
|
|
349
|
+
setContextValue(prev => ({
|
|
350
|
+
...prev,
|
|
351
|
+
instances: {
|
|
352
|
+
...prev.instances,
|
|
353
|
+
[id]: {
|
|
354
|
+
...prev.instances[id],
|
|
355
|
+
user: result.user || null,
|
|
356
|
+
isAuthenticated: result.isValid
|
|
357
|
+
}
|
|
348
358
|
}
|
|
349
|
-
}
|
|
350
|
-
}
|
|
359
|
+
}));
|
|
360
|
+
}
|
|
351
361
|
return result;
|
|
352
362
|
}
|
|
363
|
+
});
|
|
364
|
+
instancesMap[instanceConfig.id] = {
|
|
365
|
+
config: fullConfig,
|
|
366
|
+
apiClient,
|
|
367
|
+
authService,
|
|
368
|
+
user,
|
|
369
|
+
isAuthenticated,
|
|
370
|
+
isLoading: true, // Start as loading
|
|
371
|
+
...createInstanceFunctions(instanceConfig.id)
|
|
353
372
|
};
|
|
354
373
|
}
|
|
355
374
|
}
|
|
@@ -454,6 +473,10 @@ function PubflowProvider({ children, config, instances, defaultInstance = 'defau
|
|
|
454
473
|
}
|
|
455
474
|
};
|
|
456
475
|
initialize();
|
|
476
|
+
// Cleanup function
|
|
477
|
+
return () => {
|
|
478
|
+
isMounted = false;
|
|
479
|
+
};
|
|
457
480
|
}, [config, instances, defaultInstance, handleSessionExpired, handleSessionRefreshed]);
|
|
458
481
|
// Show loading state
|
|
459
482
|
if (!isInitialized) {
|