@insforge/react 0.6.3 → 0.6.4
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/atoms.cjs.map +1 -1
- package/dist/atoms.js.map +1 -1
- package/dist/components.cjs.map +1 -1
- package/dist/components.js.map +1 -1
- package/dist/forms.cjs.map +1 -1
- package/dist/forms.js.map +1 -1
- package/dist/hooks.cjs.map +1 -1
- package/dist/hooks.js.map +1 -1
- package/dist/index.cjs +33 -16
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +33 -16
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -69,6 +69,7 @@ var InsforgeManager = class _InsforgeManager {
|
|
|
69
69
|
// State storage
|
|
70
70
|
user = null;
|
|
71
71
|
isLoaded = false;
|
|
72
|
+
isInitializing = false;
|
|
72
73
|
sdk;
|
|
73
74
|
listeners = /* @__PURE__ */ new Set();
|
|
74
75
|
// Config
|
|
@@ -79,6 +80,11 @@ var InsforgeManager = class _InsforgeManager {
|
|
|
79
80
|
constructor(config) {
|
|
80
81
|
this.config = config;
|
|
81
82
|
this.sdk = createClient({ baseUrl: config.baseUrl });
|
|
83
|
+
const session = this.sdk.auth.getCurrentSession();
|
|
84
|
+
if (!session.data?.session?.accessToken) {
|
|
85
|
+
this.isLoaded = true;
|
|
86
|
+
this.user = null;
|
|
87
|
+
}
|
|
82
88
|
}
|
|
83
89
|
// Public access method (Singleton core)
|
|
84
90
|
static getInstance(config) {
|
|
@@ -102,8 +108,17 @@ var InsforgeManager = class _InsforgeManager {
|
|
|
102
108
|
}
|
|
103
109
|
// Public initialization method
|
|
104
110
|
async initialize() {
|
|
105
|
-
if (
|
|
111
|
+
if (this.isLoaded) {
|
|
112
|
+
return;
|
|
113
|
+
}
|
|
114
|
+
if (this.isInitializing) {
|
|
115
|
+
return;
|
|
116
|
+
}
|
|
117
|
+
this.isInitializing = true;
|
|
118
|
+
try {
|
|
106
119
|
await this.loadAuthState();
|
|
120
|
+
} finally {
|
|
121
|
+
this.isInitializing = false;
|
|
107
122
|
}
|
|
108
123
|
}
|
|
109
124
|
// Get current state
|
|
@@ -412,22 +427,22 @@ var InsforgeManager = class _InsforgeManager {
|
|
|
412
427
|
getSDK() {
|
|
413
428
|
return this.sdk;
|
|
414
429
|
}
|
|
415
|
-
// Handle
|
|
416
|
-
|
|
430
|
+
// Handle auth redirect after successful authentication
|
|
431
|
+
// Works for all auth sources: OAuth providers, cloud hosting sign-in, email verification
|
|
432
|
+
handleAuthRedirect(isLoaded, user) {
|
|
417
433
|
if (!isLoaded || this.hasProcessedCallbackRef) {
|
|
418
434
|
return false;
|
|
419
435
|
}
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
this.hasProcessedCallbackRef
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
}
|
|
430
|
-
return true;
|
|
436
|
+
if (user && this.config.afterSignInUrl) {
|
|
437
|
+
const currentPath = window.location.pathname + window.location.search;
|
|
438
|
+
const targetPath = this.config.afterSignInUrl;
|
|
439
|
+
if (currentPath !== targetPath && !this.hasProcessedCallbackRef) {
|
|
440
|
+
this.hasProcessedCallbackRef = true;
|
|
441
|
+
setTimeout(() => {
|
|
442
|
+
window.location.href = targetPath;
|
|
443
|
+
}, 100);
|
|
444
|
+
return true;
|
|
445
|
+
}
|
|
431
446
|
}
|
|
432
447
|
return false;
|
|
433
448
|
}
|
|
@@ -464,11 +479,13 @@ function InsforgeProviderCore({
|
|
|
464
479
|
setState(newState);
|
|
465
480
|
});
|
|
466
481
|
void manager.initialize();
|
|
467
|
-
return
|
|
482
|
+
return () => {
|
|
483
|
+
unsubscribe();
|
|
484
|
+
};
|
|
468
485
|
}, [manager]);
|
|
469
486
|
useEffect(() => {
|
|
470
487
|
if (typeof window !== "undefined") {
|
|
471
|
-
manager.
|
|
488
|
+
manager.handleAuthRedirect(state.isLoaded, state.user);
|
|
472
489
|
}
|
|
473
490
|
}, [manager, state.isLoaded, state.user]);
|
|
474
491
|
const contextValue = useMemo(
|