@insforge/sdk 1.1.2-edge.2 → 1.1.2-edge.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/index.d.mts CHANGED
@@ -53,7 +53,7 @@ interface TokenStorage {
53
53
  removeItem(key: string): void | Promise<void>;
54
54
  }
55
55
  interface AuthSession {
56
- user: UserSchema | null;
56
+ user: UserSchema;
57
57
  accessToken: string;
58
58
  expiresAt?: Date;
59
59
  }
package/dist/index.d.ts CHANGED
@@ -53,7 +53,7 @@ interface TokenStorage {
53
53
  removeItem(key: string): void | Promise<void>;
54
54
  }
55
55
  interface AuthSession {
56
- user: UserSchema | null;
56
+ user: UserSchema;
57
57
  accessToken: string;
58
58
  expiresAt?: Date;
59
59
  }
package/dist/index.js CHANGED
@@ -613,23 +613,23 @@ var Auth = class {
613
613
  return { data: { session: null }, error: null };
614
614
  }
615
615
  try {
616
- const existingSession = this.tokenManager.getSession();
617
- if (existingSession) {
618
- this.http.setAuthToken(existingSession.accessToken);
619
- return { data: { session: existingSession }, error: null };
620
- }
621
- const accessToken = this.tokenManager.getAccessToken();
622
- if (accessToken) {
623
- this.http.setAuthToken(accessToken);
624
- try {
625
- const response = await this.http.get("/api/auth/sessions/current");
626
- const session = { accessToken, user: response.user };
627
- this.tokenManager.saveSession(session);
628
- return { data: { session }, error: null };
629
- } catch (error) {
630
- this.tokenManager.clearSession();
631
- this.http.setAuthToken(null);
616
+ const session = this.tokenManager.getSession();
617
+ if (session) {
618
+ this.http.setAuthToken(session.accessToken);
619
+ if (Object.keys(session.user).length === 0) {
620
+ try {
621
+ const authResponse = await this.http.get(
622
+ "/api/auth/sessions/current",
623
+ { credentials: "include" }
624
+ );
625
+ if (authResponse.user) {
626
+ session.user = authResponse.user;
627
+ this.tokenManager.setUser(authResponse.user);
628
+ }
629
+ } catch {
630
+ }
632
631
  }
632
+ return { data: { session }, error: null };
633
633
  }
634
634
  if (typeof window !== "undefined") {
635
635
  try {
@@ -661,9 +661,9 @@ var Auth = class {
661
661
  if (error instanceof InsForgeError) {
662
662
  if (error.statusCode === 404) {
663
663
  this.tokenManager.setStorageMode();
664
- const session = this.tokenManager.getSession();
665
- if (session) {
666
- return { data: { session }, error: null };
664
+ const session2 = this.tokenManager.getSession();
665
+ if (session2) {
666
+ return { data: { session: session2 }, error: null };
667
667
  }
668
668
  return { data: { session: null }, error: null };
669
669
  }
@@ -1843,7 +1843,7 @@ var InsForgeClient = class {
1843
1843
  this.http.setAuthToken(config.edgeFunctionToken);
1844
1844
  this.tokenManager.saveSession({
1845
1845
  accessToken: config.edgeFunctionToken,
1846
- user: null
1846
+ user: {}
1847
1847
  });
1848
1848
  }
1849
1849
  const existingSession = this.tokenManager.getSession();