@steroidsjs/core 2.2.91 → 2.2.93

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.
@@ -10,6 +10,8 @@ interface IHttpRequestOptions {
10
10
  export default class HttpComponent {
11
11
  accessTokenKey: string;
12
12
  apiUrl: string;
13
+ clientStorageName: string;
14
+ clientStorageExpiresIn: number;
13
15
  _accessToken: any;
14
16
  _axios: any;
15
17
  _components: any;
@@ -69,6 +69,8 @@ var HttpComponent = /** @class */ (function () {
69
69
  //|| process.env.APP_BACKEND_URL
70
70
  || (!process.env.IS_SSR ? window.location.protocol + '//' + window.location.host : '');
71
71
  this.accessTokenKey = config.accessTokenKey || 'accessToken';
72
+ this.clientStorageName = config.clientStorageName || this._components.clientStorage.STORAGE_COOKIE;
73
+ this.clientStorageExpiresIn = config.clientStorageExpiresIn || 180;
72
74
  this._lazyRequests = {};
73
75
  this._axios = null;
74
76
  this._csrfToken = null;
@@ -101,7 +103,7 @@ var HttpComponent = /** @class */ (function () {
101
103
  }
102
104
  if (!(this._accessToken === false)) return [3 /*break*/, 4];
103
105
  clientStorage = this._components.clientStorage;
104
- tokenValue = clientStorage.get(this.accessTokenKey, clientStorage.STORAGE_COOKIE)
106
+ tokenValue = clientStorage.get(this.accessTokenKey, this.clientStorageName)
105
107
  || clientStorage.get(this.accessTokenKey)
106
108
  || null;
107
109
  // client storage method 'get' could be asynchronous
@@ -118,7 +120,7 @@ var HttpComponent = /** @class */ (function () {
118
120
  // client storage method 'get' could be asynchronous
119
121
  _a._accessToken = _b;
120
122
  if (this._accessToken) {
121
- clientStorage.set(this.accessTokenKey, this._accessToken, clientStorage.STORAGE_COOKIE, 180);
123
+ clientStorage.set(this.accessTokenKey, this._accessToken, this.clientStorageName, this.clientStorageExpiresIn);
122
124
  }
123
125
  _c.label = 4;
124
126
  case 4:
@@ -140,7 +142,7 @@ var HttpComponent = /** @class */ (function () {
140
142
  HttpComponent.prototype.removeAccessToken = function () {
141
143
  this._accessToken = null;
142
144
  this.resetConfig();
143
- this._components.clientStorage.remove(this.accessTokenKey, this._components.clientStorage.STORAGE_COOKIE);
145
+ this._components.clientStorage.remove(this.accessTokenKey, this.clientStorageName);
144
146
  };
145
147
  /**
146
148
  * @param {string} value
@@ -148,7 +150,7 @@ var HttpComponent = /** @class */ (function () {
148
150
  HttpComponent.prototype.setAccessToken = function (value) {
149
151
  this._accessToken = value;
150
152
  this.resetConfig();
151
- this._components.clientStorage.set(this.accessTokenKey, value, this._components.clientStorage.STORAGE_COOKIE, 180);
153
+ this._components.clientStorage.set(this.accessTokenKey, value, this.clientStorageName, this.clientStorageExpiresIn);
152
154
  };
153
155
  /**
154
156
  * @returns {string}
@@ -161,7 +163,7 @@ var HttpComponent = /** @class */ (function () {
161
163
  case 0:
162
164
  if (!(this._accessToken === false)) return [3 /*break*/, 2];
163
165
  _a = this;
164
- return [4 /*yield*/, this._components.clientStorage.get(this.accessTokenKey)];
166
+ return [4 /*yield*/, this._components.clientStorage.get(this.accessTokenKey, this.clientStorageName)];
165
167
  case 1:
166
168
  _a._accessToken = (_b.sent()) || null;
167
169
  _b.label = 2;
@@ -76,7 +76,7 @@ var JwtHttpComponent = /** @class */ (function (_super) {
76
76
  config = _super.prototype.getAxiosConfig.call(this);
77
77
  if (!!this._refreshToken) return [3 /*break*/, 4];
78
78
  clientStorage = this._components.clientStorage;
79
- tokenValue = clientStorage.get(this.refreshTokenKey, clientStorage.STORAGE_COOKIE)
79
+ tokenValue = clientStorage.get(this.refreshTokenKey, this.clientStorageName)
80
80
  || clientStorage.get(this.refreshTokenKey)
81
81
  || null;
82
82
  _a = this;
@@ -91,7 +91,7 @@ var JwtHttpComponent = /** @class */ (function (_super) {
91
91
  case 3:
92
92
  _a._refreshToken = _b;
93
93
  if (this._refreshToken) {
94
- clientStorage.set(this.refreshTokenKey, this._refreshToken, clientStorage.STORAGE_COOKIE, 180);
94
+ clientStorage.set(this.refreshTokenKey, this._refreshToken, this.clientStorageName, this.clientStorageExpiresIn);
95
95
  }
96
96
  _c.label = 4;
97
97
  case 4: return [2 /*return*/, config];
@@ -104,20 +104,23 @@ var JwtHttpComponent = /** @class */ (function (_super) {
104
104
  axiosInstance.interceptors.response.use(function (config) { return config; }, function (error) { return __awaiter(_this, void 0, void 0, function () {
105
105
  var originalRequest, store, response, accessToken;
106
106
  var _a;
107
- var _b;
108
- return __generator(this, function (_c) {
109
- switch (_c.label) {
107
+ var _b, _c;
108
+ return __generator(this, function (_d) {
109
+ switch (_d.label) {
110
110
  case 0:
111
111
  originalRequest = error.config;
112
- if (!(error.response.status === 401 && error.config && !error.config._isRetry)) return [3 /*break*/, 2];
112
+ if (!(error.response.status === 401
113
+ && error.config
114
+ && !error.config._isRetry
115
+ && originalRequest.url !== this.getUrl((_b = this.refreshTokenRequest) === null || _b === void 0 ? void 0 : _b.url))) return [3 /*break*/, 2];
113
116
  this.removeAccessToken();
114
117
  store = this._components.store;
115
118
  return [4 /*yield*/, this.send(this.refreshTokenRequest.method, this.refreshTokenRequest.url, (_a = {},
116
119
  _a[this.refreshTokenKey] = this._refreshToken,
117
120
  _a))];
118
121
  case 1:
119
- response = _c.sent();
120
- accessToken = (_b = response === null || response === void 0 ? void 0 : response.data) === null || _b === void 0 ? void 0 : _b[this.accessTokenKey];
122
+ response = _d.sent();
123
+ accessToken = (_c = response === null || response === void 0 ? void 0 : response.data) === null || _c === void 0 ? void 0 : _c[this.accessTokenKey];
121
124
  if (accessToken) {
122
125
  this.setAccessToken(accessToken);
123
126
  originalRequest._isRetry = true;
@@ -125,7 +128,7 @@ var JwtHttpComponent = /** @class */ (function (_super) {
125
128
  return [2 /*return*/, axiosInstance.request(originalRequest)];
126
129
  }
127
130
  store.dispatch(auth_1.logout());
128
- _c.label = 2;
131
+ _d.label = 2;
129
132
  case 2: throw error;
130
133
  }
131
134
  });
@@ -153,12 +156,12 @@ var JwtHttpComponent = /** @class */ (function (_super) {
153
156
  JwtHttpComponent.prototype.removeRefreshToken = function () {
154
157
  this._refreshToken = null;
155
158
  this.resetConfig();
156
- this._components.clientStorage.remove(this.refreshTokenKey, this._components.clientStorage.STORAGE_COOKIE);
159
+ this._components.clientStorage.remove(this.refreshTokenKey, this.clientStorageName);
157
160
  };
158
161
  JwtHttpComponent.prototype.setRefreshToken = function (value) {
159
162
  this._refreshToken = value;
160
163
  this.resetConfig();
161
- this._components.clientStorage.set(this.refreshTokenKey, value, this._components.clientStorage.STORAGE_COOKIE, 180);
164
+ this._components.clientStorage.set(this.refreshTokenKey, value, this.clientStorageName, this.clientStorageExpiresIn);
162
165
  };
163
166
  JwtHttpComponent.prototype.getRefreshToken = function () {
164
167
  return __awaiter(this, void 0, void 0, function () {
@@ -168,7 +171,7 @@ var JwtHttpComponent = /** @class */ (function (_super) {
168
171
  case 0:
169
172
  if (!(this._refreshToken === false)) return [3 /*break*/, 2];
170
173
  _a = this;
171
- return [4 /*yield*/, this._components.clientStorage.get(this.refreshTokenKey)];
174
+ return [4 /*yield*/, this._components.clientStorage.get(this.refreshTokenKey, this.clientStorageName)];
172
175
  case 1:
173
176
  _a._refreshToken = (_b.sent()) || null;
174
177
  _b.label = 2;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@steroidsjs/core",
3
- "version": "2.2.91",
3
+ "version": "2.2.93",
4
4
  "description": "",
5
5
  "author": "Vladimir Kozhin <hello@kozhindev.com>",
6
6
  "repository": {