@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/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 = null;
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
- const session = this.sdk.auth.getCurrentSession();
84
- if (!session.data?.session?.accessToken) {
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: !!this.user
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: null,
527
+ user: void 0,
528
+ userId: void 0,
527
529
  isLoaded: false,
528
- isSignedIn: false,
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 { isSignedIn, isLoaded, user } = useInsforge();
2510
+ const { userId, user } = useInsforge();
2509
2511
  const resolvedRedirectTo = useMemo(() => resolveAuthPath(redirectTo), [redirectTo]);
2510
2512
  useEffect(() => {
2511
- if (isLoaded && !isSignedIn) {
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 (isLoaded && isSignedIn && condition && user) {
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
- }, [isLoaded, isSignedIn, resolvedRedirectTo, condition, user, onRedirect]);
2527
- if (!isLoaded) {
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 (!isSignedIn) {
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 { isSignedIn, isLoaded } = useInsforge();
2540
- if (!isLoaded) {
2541
- return null;
2542
- }
2543
- if (!isSignedIn) {
2544
- return null;
2541
+ const { userId } = useInsforge();
2542
+ if (userId) {
2543
+ return /* @__PURE__ */ jsx(Fragment, { children });
2545
2544
  }
2546
- return /* @__PURE__ */ jsx(Fragment, { children });
2545
+ return null;
2547
2546
  }
2548
2547
  function SignedOut({ children }) {
2549
- const { isSignedIn, isLoaded } = useInsforge();
2550
- if (!isLoaded) {
2551
- return null;
2548
+ const { userId } = useInsforge();
2549
+ if (userId === null) {
2550
+ return /* @__PURE__ */ jsx(Fragment, { children });
2552
2551
  }
2553
- if (isSignedIn) {
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();