@evergis/api 4.1.51 → 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.esm.js +15 -6
- package/dist/api.esm.js.map +1 -1
- package/dist/index.js +15 -6
- 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,11 +2784,10 @@ class Api extends EventEmitter {
|
|
|
2784
2784
|
http;
|
|
2785
2785
|
wsUrl;
|
|
2786
2786
|
urlPath;
|
|
2787
|
-
refreshingToken;
|
|
2787
|
+
refreshingToken = false;
|
|
2788
2788
|
constructor({ url, wsUrl, wsKeepAlive, snappingHubUrl, http, urlPath, httpOptions, }) {
|
|
2789
2789
|
super();
|
|
2790
2790
|
const { hooks } = httpOptions || {};
|
|
2791
|
-
this.refreshingToken = false;
|
|
2792
2791
|
this.http =
|
|
2793
2792
|
http ||
|
|
2794
2793
|
new HttpClient({
|
|
@@ -2817,10 +2816,15 @@ class Api extends EventEmitter {
|
|
|
2817
2816
|
retryCount === 1) {
|
|
2818
2817
|
switch (error.response.status) {
|
|
2819
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;
|
|
2820
2825
|
try {
|
|
2821
2826
|
const refreshToken = window.localStorage.getItem(STORAGE_REFRESH_TOKEN_KEY);
|
|
2822
|
-
if (
|
|
2823
|
-
this.refreshingToken = true;
|
|
2827
|
+
if (refreshToken) {
|
|
2824
2828
|
const refreshTokenResponse = await this.account.refreshToken({
|
|
2825
2829
|
refreshToken,
|
|
2826
2830
|
});
|
|
@@ -2829,12 +2833,17 @@ class Api extends EventEmitter {
|
|
|
2829
2833
|
window.localStorage.setItem(STORAGE_REFRESH_TOKEN_KEY, refreshTokenResponse.refreshToken);
|
|
2830
2834
|
}
|
|
2831
2835
|
request.headers?.set("Authorization", `Bearer ${refreshTokenResponse.token || ""}`);
|
|
2832
|
-
|
|
2836
|
+
}
|
|
2837
|
+
else {
|
|
2838
|
+
await this.logout();
|
|
2833
2839
|
}
|
|
2834
2840
|
}
|
|
2835
2841
|
catch (error) {
|
|
2836
2842
|
await this.logout();
|
|
2837
2843
|
}
|
|
2844
|
+
finally {
|
|
2845
|
+
this.refreshingToken = false;
|
|
2846
|
+
}
|
|
2838
2847
|
break;
|
|
2839
2848
|
}
|
|
2840
2849
|
}
|