shared-ritm 1.3.64 → 1.3.66

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.
@@ -4,7 +4,6 @@ export declare enum ApiServiceType {
4
4
  }
5
5
  export default class ApiService {
6
6
  private axiosInstance;
7
- private isRefreshing;
8
7
  private refreshSubscribers;
9
8
  constructor();
10
9
  private setAccessToken;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "shared-ritm",
3
- "version": "1.3.64",
3
+ "version": "1.3.66",
4
4
  "private": false,
5
5
  "files": [
6
6
  "dist",
@@ -1,6 +1,8 @@
1
1
  import axios, { AxiosError, AxiosInstance, AxiosRequestConfig, AxiosResponse, InternalAxiosRequestConfig } from 'axios'
2
2
  import { Api_Auth_Login } from '@/api/types/Api_Auth'
3
3
 
4
+ let isRefreshing = false
5
+
4
6
  interface Api_Auth_Refresh {
5
7
  accessToken: string
6
8
  }
@@ -11,8 +13,6 @@ export enum ApiServiceType {
11
13
 
12
14
  export default class ApiService {
13
15
  private axiosInstance: AxiosInstance
14
-
15
- private isRefreshing = false
16
16
  private refreshSubscribers: any[] = []
17
17
 
18
18
  constructor() {
@@ -45,27 +45,27 @@ export default class ApiService {
45
45
  if (
46
46
  error.response?.status !== 401 ||
47
47
  originalRequest.url === '/v2/auth/refresh' ||
48
- originalRequest.url === '/v2/login'
48
+ originalRequest.url === '/v2/login' ||
49
+ originalRequest._retry
49
50
  ) {
50
- return Promise.reject(error)
51
- }
52
-
53
- if (originalRequest._retry) {
51
+ alert('sssssss' + originalRequest.url)
54
52
  return Promise.reject(error)
55
53
  }
56
54
 
57
55
  originalRequest._retry = true
58
56
 
59
- if (this.isRefreshing) {
57
+ alert(isRefreshing)
58
+
59
+ if (isRefreshing) {
60
+ alert(originalRequest.url)
60
61
  return new Promise(resolve => {
61
62
  this.subscribeTokenRefresh(() => resolve(this.axiosInstance(originalRequest)))
62
63
  })
63
64
  }
64
65
 
65
- this.isRefreshing = true
66
+ isRefreshing = true
66
67
 
67
68
  try {
68
- alert(`refresh ${this.isRefreshing}`)
69
69
  const response = await this.refresh()
70
70
 
71
71
  const newToken = response.accessToken
@@ -75,8 +75,8 @@ export default class ApiService {
75
75
  }
76
76
 
77
77
  this.setAccessToken(newToken)
78
- this.onRefreshed(newToken)
79
- this.isRefreshing = false
78
+ this.onRefreshed()
79
+ isRefreshing = false
80
80
  return this.axiosInstance(originalRequest)
81
81
  } catch (e) {
82
82
  this.logoutUser()
@@ -105,13 +105,13 @@ export default class ApiService {
105
105
  return this.post<null, Api_Auth_Login>(`/v2/auth/refresh`, null)
106
106
  }
107
107
 
108
- private onRefreshed(token: string) {
109
- this.refreshSubscribers.forEach(cb => cb(token))
108
+ private onRefreshed() {
109
+ this.refreshSubscribers.forEach(cb => cb())
110
110
  this.refreshSubscribers = []
111
111
  }
112
112
 
113
113
  public logoutUser(): any {
114
- this.isRefreshing = false
114
+ isRefreshing = false
115
115
  this.post<any, any>(`/v2/logout`, {})
116
116
  this.removeToken()
117
117
  window.location.href = '/sign-in'