@evergis/api 4.1.52 → 4.1.53

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/Api.d.ts CHANGED
@@ -57,6 +57,7 @@ export declare class Api extends EventEmitter {
57
57
  protected readonly http: HttpClient;
58
58
  private readonly wsUrl;
59
59
  private readonly urlPath;
60
+ private refreshingToken;
60
61
  constructor({ url, wsUrl, wsKeepAlive, snappingHubUrl, http, urlPath, httpOptions, }: ApiParams);
61
62
  get isShared(): boolean;
62
63
  get isPresentation(): boolean;
package/dist/api.esm.js CHANGED
@@ -746,7 +746,7 @@ class Account extends AccountService {
746
746
  }
747
747
  return userInfo;
748
748
  }
749
- async login(params, authParams = {}, useJwt = false) {
749
+ async login(params, authParams = {}, useJwt = true) {
750
750
  if (params) {
751
751
  const response = await super.authenticate(authParams, params);
752
752
  if (response && useJwt) {
@@ -2783,6 +2783,7 @@ class Api extends EventEmitter {
2783
2783
  http;
2784
2784
  wsUrl;
2785
2785
  urlPath;
2786
+ refreshingToken = false;
2786
2787
  constructor({ url, wsUrl, wsKeepAlive, snappingHubUrl, http, urlPath, httpOptions, }) {
2787
2788
  super();
2788
2789
  const { hooks } = httpOptions || {};
@@ -2814,6 +2815,12 @@ class Api extends EventEmitter {
2814
2815
  retryCount === 1) {
2815
2816
  switch (error.response.status) {
2816
2817
  case 401:
2818
+ if (this.refreshingToken) {
2819
+ const currentToken = window.localStorage.getItem(STORAGE_TOKEN_KEY);
2820
+ request.headers?.set("Authorization", `Bearer ${currentToken || ""}`);
2821
+ return;
2822
+ }
2823
+ this.refreshingToken = true;
2817
2824
  try {
2818
2825
  const refreshToken = window.localStorage.getItem(STORAGE_REFRESH_TOKEN_KEY);
2819
2826
  if (refreshToken) {
@@ -2826,10 +2833,16 @@ class Api extends EventEmitter {
2826
2833
  }
2827
2834
  request.headers?.set("Authorization", `Bearer ${refreshTokenResponse.token || ""}`);
2828
2835
  }
2836
+ else {
2837
+ await this.logout();
2838
+ }
2829
2839
  }
2830
2840
  catch (error) {
2831
2841
  await this.logout();
2832
2842
  }
2843
+ finally {
2844
+ this.refreshingToken = false;
2845
+ }
2833
2846
  break;
2834
2847
  }
2835
2848
  }