@evergis/api 4.1.52 → 4.1.54
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/LICENSE +21 -21
- package/README.md +12 -12
- package/dist/Api.d.ts +1 -0
- package/dist/api.esm.js +14 -1
- package/dist/api.esm.js.map +1 -1
- package/dist/index.js +14 -1
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
package/dist/index.js
CHANGED
|
@@ -747,7 +747,7 @@ class Account extends AccountService {
|
|
|
747
747
|
}
|
|
748
748
|
return userInfo;
|
|
749
749
|
}
|
|
750
|
-
async login(params, authParams = {}, useJwt =
|
|
750
|
+
async login(params, authParams = {}, useJwt = true) {
|
|
751
751
|
if (params) {
|
|
752
752
|
const response = await super.authenticate(authParams, params);
|
|
753
753
|
if (response && useJwt) {
|
|
@@ -2784,6 +2784,7 @@ class Api extends EventEmitter {
|
|
|
2784
2784
|
http;
|
|
2785
2785
|
wsUrl;
|
|
2786
2786
|
urlPath;
|
|
2787
|
+
refreshingToken = false;
|
|
2787
2788
|
constructor({ url, wsUrl, wsKeepAlive, snappingHubUrl, http, urlPath, httpOptions, }) {
|
|
2788
2789
|
super();
|
|
2789
2790
|
const { hooks } = httpOptions || {};
|
|
@@ -2815,6 +2816,12 @@ class Api extends EventEmitter {
|
|
|
2815
2816
|
retryCount === 1) {
|
|
2816
2817
|
switch (error.response.status) {
|
|
2817
2818
|
case 401:
|
|
2819
|
+
if (this.refreshingToken) {
|
|
2820
|
+
const currentToken = window.localStorage.getItem(STORAGE_TOKEN_KEY);
|
|
2821
|
+
request.headers?.set("Authorization", `Bearer ${currentToken || ""}`);
|
|
2822
|
+
return;
|
|
2823
|
+
}
|
|
2824
|
+
this.refreshingToken = true;
|
|
2818
2825
|
try {
|
|
2819
2826
|
const refreshToken = window.localStorage.getItem(STORAGE_REFRESH_TOKEN_KEY);
|
|
2820
2827
|
if (refreshToken) {
|
|
@@ -2827,10 +2834,16 @@ class Api extends EventEmitter {
|
|
|
2827
2834
|
}
|
|
2828
2835
|
request.headers?.set("Authorization", `Bearer ${refreshTokenResponse.token || ""}`);
|
|
2829
2836
|
}
|
|
2837
|
+
else {
|
|
2838
|
+
await this.logout();
|
|
2839
|
+
}
|
|
2830
2840
|
}
|
|
2831
2841
|
catch (error) {
|
|
2832
2842
|
await this.logout();
|
|
2833
2843
|
}
|
|
2844
|
+
finally {
|
|
2845
|
+
this.refreshingToken = false;
|
|
2846
|
+
}
|
|
2834
2847
|
break;
|
|
2835
2848
|
}
|
|
2836
2849
|
}
|