@insforge/react 0.6.4 → 0.6.5
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 +3 -2
- package/dist/atoms.cjs.map +1 -1
- package/dist/atoms.js +3 -2
- package/dist/atoms.js.map +1 -1
- package/dist/components.cjs +17 -22
- package/dist/components.cjs.map +1 -1
- package/dist/components.d.cts +16 -0
- package/dist/components.d.ts +16 -0
- package/dist/components.js +17 -22
- package/dist/components.js.map +1 -1
- package/dist/forms.cjs +3 -2
- package/dist/forms.cjs.map +1 -1
- package/dist/forms.js +3 -2
- package/dist/forms.js.map +1 -1
- package/dist/hooks.cjs +3 -2
- package/dist/hooks.cjs.map +1 -1
- package/dist/hooks.d.cts +2 -2
- package/dist/hooks.d.ts +2 -2
- package/dist/hooks.js +3 -2
- package/dist/hooks.js.map +1 -1
- package/dist/index.cjs +25 -29
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +25 -29
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
package/dist/index.js
CHANGED
|
@@ -67,7 +67,7 @@ var InsforgeManager = class _InsforgeManager {
|
|
|
67
67
|
// Static private instance
|
|
68
68
|
static instance = null;
|
|
69
69
|
// State storage
|
|
70
|
-
user =
|
|
70
|
+
user = void 0;
|
|
71
71
|
isLoaded = false;
|
|
72
72
|
isInitializing = false;
|
|
73
73
|
sdk;
|
|
@@ -80,11 +80,8 @@ var InsforgeManager = class _InsforgeManager {
|
|
|
80
80
|
constructor(config) {
|
|
81
81
|
this.config = config;
|
|
82
82
|
this.sdk = createClient({ baseUrl: config.baseUrl });
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
this.isLoaded = true;
|
|
86
|
-
this.user = null;
|
|
87
|
-
}
|
|
83
|
+
this.user = void 0;
|
|
84
|
+
this.isLoaded = false;
|
|
88
85
|
}
|
|
89
86
|
// Public access method (Singleton core)
|
|
90
87
|
static getInstance(config) {
|
|
@@ -123,10 +120,13 @@ var InsforgeManager = class _InsforgeManager {
|
|
|
123
120
|
}
|
|
124
121
|
// Get current state
|
|
125
122
|
getState() {
|
|
123
|
+
const userId = this.user === void 0 ? void 0 : this.user === null ? null : this.user.id;
|
|
124
|
+
const isSignedIn = this.user === void 0 ? void 0 : this.user !== null;
|
|
126
125
|
return {
|
|
127
126
|
user: this.user,
|
|
127
|
+
userId,
|
|
128
128
|
isLoaded: this.isLoaded,
|
|
129
|
-
isSignedIn
|
|
129
|
+
isSignedIn
|
|
130
130
|
};
|
|
131
131
|
}
|
|
132
132
|
// Subscription mechanism
|
|
@@ -492,6 +492,7 @@ function InsforgeProviderCore({
|
|
|
492
492
|
() => ({
|
|
493
493
|
// State from Manager
|
|
494
494
|
user: state.user,
|
|
495
|
+
userId: state.userId,
|
|
495
496
|
isLoaded: state.isLoaded,
|
|
496
497
|
isSignedIn: state.isSignedIn,
|
|
497
498
|
// Methods delegated to Manager
|
|
@@ -523,9 +524,10 @@ function useInsforge() {
|
|
|
523
524
|
const context = useContext(InsforgeContext);
|
|
524
525
|
if (!context) {
|
|
525
526
|
return {
|
|
526
|
-
user:
|
|
527
|
+
user: void 0,
|
|
528
|
+
userId: void 0,
|
|
527
529
|
isLoaded: false,
|
|
528
|
-
isSignedIn:
|
|
530
|
+
isSignedIn: void 0,
|
|
529
531
|
setUser: () => {
|
|
530
532
|
},
|
|
531
533
|
signIn: () => Promise.resolve({ error: "SSR mode" }),
|
|
@@ -2505,16 +2507,16 @@ function Protect({
|
|
|
2505
2507
|
condition,
|
|
2506
2508
|
onRedirect
|
|
2507
2509
|
}) {
|
|
2508
|
-
const {
|
|
2510
|
+
const { userId, user } = useInsforge();
|
|
2509
2511
|
const resolvedRedirectTo = useMemo(() => resolveAuthPath(redirectTo), [redirectTo]);
|
|
2510
2512
|
useEffect(() => {
|
|
2511
|
-
if (
|
|
2513
|
+
if (userId === null) {
|
|
2512
2514
|
if (onRedirect) {
|
|
2513
2515
|
onRedirect(resolvedRedirectTo);
|
|
2514
2516
|
} else {
|
|
2515
2517
|
window.location.href = resolvedRedirectTo;
|
|
2516
2518
|
}
|
|
2517
|
-
} else if (
|
|
2519
|
+
} else if (userId && condition && user) {
|
|
2518
2520
|
if (!condition(user)) {
|
|
2519
2521
|
if (onRedirect) {
|
|
2520
2522
|
onRedirect(resolvedRedirectTo);
|
|
@@ -2523,11 +2525,11 @@ function Protect({
|
|
|
2523
2525
|
}
|
|
2524
2526
|
}
|
|
2525
2527
|
}
|
|
2526
|
-
}, [
|
|
2527
|
-
if (
|
|
2528
|
+
}, [userId, resolvedRedirectTo, condition, user, onRedirect]);
|
|
2529
|
+
if (userId === void 0) {
|
|
2528
2530
|
return fallback || /* @__PURE__ */ jsx("div", { className: "insforge-loading", children: "Loading..." });
|
|
2529
2531
|
}
|
|
2530
|
-
if (
|
|
2532
|
+
if (userId === null) {
|
|
2531
2533
|
return fallback || null;
|
|
2532
2534
|
}
|
|
2533
2535
|
if (condition && user && !condition(user)) {
|
|
@@ -2536,24 +2538,18 @@ function Protect({
|
|
|
2536
2538
|
return /* @__PURE__ */ jsx(Fragment, { children });
|
|
2537
2539
|
}
|
|
2538
2540
|
function SignedIn({ children }) {
|
|
2539
|
-
const {
|
|
2540
|
-
if (
|
|
2541
|
-
return
|
|
2542
|
-
}
|
|
2543
|
-
if (!isSignedIn) {
|
|
2544
|
-
return null;
|
|
2541
|
+
const { userId } = useInsforge();
|
|
2542
|
+
if (userId) {
|
|
2543
|
+
return /* @__PURE__ */ jsx(Fragment, { children });
|
|
2545
2544
|
}
|
|
2546
|
-
return
|
|
2545
|
+
return null;
|
|
2547
2546
|
}
|
|
2548
2547
|
function SignedOut({ children }) {
|
|
2549
|
-
const {
|
|
2550
|
-
if (
|
|
2551
|
-
return
|
|
2548
|
+
const { userId } = useInsforge();
|
|
2549
|
+
if (userId === null) {
|
|
2550
|
+
return /* @__PURE__ */ jsx(Fragment, { children });
|
|
2552
2551
|
}
|
|
2553
|
-
|
|
2554
|
-
return null;
|
|
2555
|
-
}
|
|
2556
|
-
return /* @__PURE__ */ jsx(Fragment, { children });
|
|
2552
|
+
return null;
|
|
2557
2553
|
}
|
|
2558
2554
|
function SignInButton({ children, className }) {
|
|
2559
2555
|
const { afterSignInUrl, baseUrl } = useInsforge();
|