@insforge/react 1.0.2-dev.0 → 1.0.2-dev.10

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 CHANGED
@@ -535,15 +535,7 @@ var InsforgeManager = class _InsforgeManager {
535
535
  }
536
536
  this.isInitializing = true;
537
537
  try {
538
- const sessionResult = this.sdk.auth.getCurrentSession();
539
- const hasToken = !!sessionResult.data?.session?.accessToken;
540
- if (hasToken) {
541
- await this.loadAuthState();
542
- } else if (this.user === void 0) {
543
- this.user = null;
544
- this.isLoaded = true;
545
- this.notifyListeners();
546
- }
538
+ await this.loadAuthState();
547
539
  } finally {
548
540
  this.isInitializing = false;
549
541
  }
@@ -573,18 +565,7 @@ var InsforgeManager = class _InsforgeManager {
573
565
  // Called after hydration to get complete user information beyond what's in cookies
574
566
  async loadAuthState() {
575
567
  try {
576
- const sessionResult = this.sdk.auth.getCurrentSession();
577
- const session = sessionResult.data?.session;
578
- const token2 = session?.accessToken || null;
579
- if (!token2) {
580
- this.user = null;
581
- if (this.config.onAuthChange) {
582
- this.config.onAuthChange(null);
583
- }
584
- this.isLoaded = true;
585
- this.notifyListeners();
586
- return { success: false, error: "no_session" };
587
- }
568
+ console.log("[InsforgeManager] loadAuthState() - calling getCurrentUser()");
588
569
  const userResult = await this.sdk.auth.getCurrentUser();
589
570
  if (userResult.data) {
590
571
  const profile = userResult.data.profile;
@@ -596,6 +577,7 @@ var InsforgeManager = class _InsforgeManager {
596
577
  // You can add more profile fields here as needed
597
578
  };
598
579
  this.user = userData;
580
+ console.log("[InsforgeManager] loadAuthState() - user loaded:", userData.email);
599
581
  if (this.config.onAuthChange) {
600
582
  this.config.onAuthChange(userData);
601
583
  }
@@ -603,36 +585,17 @@ var InsforgeManager = class _InsforgeManager {
603
585
  this.notifyListeners();
604
586
  return { success: true };
605
587
  } else {
606
- await this.sdk.auth.signOut();
607
- if (this.config.onSignOut) {
608
- try {
609
- await this.config.onSignOut();
610
- } catch (error) {
611
- if (error instanceof Error) {
612
- console.error("[InsforgeManager] Error clearing cookie:", error.message);
613
- }
614
- }
615
- }
588
+ console.log("[InsforgeManager] loadAuthState() - no user data, error:", userResult.error);
616
589
  this.user = null;
617
590
  if (this.config.onAuthChange) {
618
591
  this.config.onAuthChange(null);
619
592
  }
620
593
  this.isLoaded = true;
621
594
  this.notifyListeners();
622
- return { success: false, error: "invalid_token" };
595
+ return { success: false, error: userResult.error?.message || "no_session" };
623
596
  }
624
597
  } catch (error) {
625
- console.error("[InsforgeManager] Token validation failed:", error);
626
- await this.sdk.auth.signOut();
627
- if (this.config.onSignOut) {
628
- try {
629
- await this.config.onSignOut();
630
- } catch (error2) {
631
- if (error2 instanceof Error) {
632
- console.error("[InsforgeManager] Error clearing cookie:", error2.message);
633
- }
634
- }
635
- }
598
+ console.error("[InsforgeManager] loadAuthState() catch error:", error);
636
599
  this.user = null;
637
600
  if (this.config.onAuthChange) {
638
601
  this.config.onAuthChange(null);