@insforge/sdk 1.1.2-edge.1 → 1.1.2-edge.2

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
@@ -613,23 +613,23 @@ var Auth = class {
613
613
  return { data: { session: null }, error: null };
614
614
  }
615
615
  try {
616
- const session = this.tokenManager.getSession();
617
- if (session) {
618
- this.http.setAuthToken(session.accessToken);
619
- if (!session.user) {
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
- }
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);
631
632
  }
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 session2 = this.tokenManager.getSession();
665
- if (session2) {
666
- return { data: { session: session2 }, error: null };
664
+ const session = this.tokenManager.getSession();
665
+ if (session) {
666
+ return { data: { session }, error: null };
667
667
  }
668
668
  return { data: { session: null }, error: null };
669
669
  }