@tapni/auth 0.0.77 → 0.0.79

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tapni/auth",
3
- "version": "0.0.77",
3
+ "version": "0.0.79",
4
4
  "type": "module",
5
5
  "main": "./dist/TapniAuth.umd.js",
6
6
  "module": "./dist/TapniAuth.es.js",
@@ -244,29 +244,34 @@ export default {
244
244
  });
245
245
  },
246
246
  async refreshTokenAction(data) {
247
- if (!this.refreshToken || this.refreshing) {
248
- console.log('return-refreshTokenAction', this.refreshToken, this.refreshing);
249
- return;
250
- }
247
+ return new Promise(async (resolve, reject) => {
248
+ console.log('auth-refreshTokenAction', data);
249
+ if (!this.refreshToken || this.refreshing) {
250
+ console.log('return-refreshTokenAction', this.refreshToken, this.refreshing);
251
+ return;
252
+ }
251
253
 
252
- this.refreshing = true;
253
- const [err, response] = await to(
254
- AuthService.refreshToken({
255
- id: data.id,
256
- refreshToken: this.refreshToken,
257
- refreshTokenAction: true
258
- }, this.$storage)
259
- );
260
- if (err && err.response && err.response.data.error === "ACCESS_DENIED") {
261
- this.logout(false);
262
- return location.reload();
263
- }
254
+ this.refreshing = true;
255
+ const [err, response] = await to(
256
+ AuthService.refreshToken({
257
+ id: data.id,
258
+ refreshToken: this.refreshToken,
259
+ refreshTokenAction: true
260
+ }, this.$storage)
261
+ );
262
+ if (err && err.response && err.response.data.error === "ACCESS_DENIED") {
263
+ this.logout(false);
264
+ return location.reload();
265
+ }
264
266
 
265
- // Set new access token
266
- if (response && response.data) {
267
- this.setToken(response.data.token);
268
- } else console.error('Invalid response setToken');
269
- this.refreshing = false;
267
+ // Set new access token
268
+ if (response && response.data) {
269
+ this.setToken(response.data.token);
270
+ EventBus.$emit("ssoEvent", { name: "setStorage", data: this.$storage });
271
+ resolve(response.data.token);
272
+ } else reject('Invalid response setToken');
273
+ this.refreshing = false;
274
+ })
270
275
  },
271
276
  async login(data) {
272
277
  const [err, response] = await to(AuthService.login(data, this.$storage));
@@ -49,6 +49,8 @@ export default {
49
49
  }
50
50
  }
51
51
 
52
+ console.log('before interceptor enter', storage, refreshTokenAction);
53
+
52
54
  // Check refresh token expiration before request is sent
53
55
  if (storage && storage.token && !refreshTokenAction) {
54
56
  const decoded = jwtDecode(storage.token)
@@ -59,10 +61,10 @@ export default {
59
61
  if (decoded.exp - 30 < Math.floor(Date.now() / 1000)) {
60
62
 
61
63
  return AuthMixin.methods.refreshTokenAction(decoded)
62
- .then(() => {
64
+ .then((token) => {
63
65
  config.headers = {
64
66
  ...config.headers,
65
- Authorization: `Bearer ${storage.token}`
67
+ Authorization: `Bearer ${token}`
66
68
  }
67
69
  return config;
68
70
  })