shared-ritm 1.3.51 → 1.3.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.
@@ -4,7 +4,6 @@ export declare enum ApiServiceType {
4
4
  }
5
5
  export default class ApiService {
6
6
  private axiosInstance;
7
- private access_token;
8
7
  private isRefreshing;
9
8
  private refreshSubscribers;
10
9
  constructor();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "shared-ritm",
3
- "version": "1.3.51",
3
+ "version": "1.3.53",
4
4
  "private": false,
5
5
  "files": [
6
6
  "dist",
@@ -12,14 +12,10 @@ export enum ApiServiceType {
12
12
  export default class ApiService {
13
13
  private axiosInstance: AxiosInstance
14
14
 
15
- private access_token: string | null = null
16
-
17
15
  private isRefreshing = false
18
16
  private refreshSubscribers: any[] = []
19
17
 
20
18
  constructor() {
21
- this.access_token = this.getAccessToken()
22
-
23
19
  this.axiosInstance = axios.create({
24
20
  baseURL: process.env.VUE_APP_BACKEND,
25
21
  headers: {
@@ -31,9 +27,7 @@ export default class ApiService {
31
27
 
32
28
  this.axiosInstance.interceptors.request.use(
33
29
  (config: InternalAxiosRequestConfig) => {
34
- if (this.access_token && config.headers) {
35
- config.headers.Authorization = `Bearer ${this.access_token}`
36
- }
30
+ config.headers.Authorization = `Bearer ${this.getAccessToken()}`
37
31
  return config
38
32
  },
39
33
  (error: AxiosError) => {
@@ -48,7 +42,7 @@ export default class ApiService {
48
42
  async error => {
49
43
  const originalRequest = error.config
50
44
 
51
- if (error.response?.status !== 401) {
45
+ if (error.response?.status !== 401 || originalRequest.url === '/v2/auth/refresh') {
52
46
  return Promise.reject(error)
53
47
  }
54
48
 
@@ -60,10 +54,7 @@ export default class ApiService {
60
54
 
61
55
  if (this.isRefreshing) {
62
56
  return new Promise(resolve => {
63
- this.subscribeTokenRefresh(token => {
64
- originalRequest.headers['Authorization'] = `Bearer ${token}`
65
- resolve(this.axiosInstance(originalRequest))
66
- })
57
+ this.subscribeTokenRefresh(() => resolve(this.axiosInstance(originalRequest)))
67
58
  })
68
59
  }
69
60
 
@@ -73,21 +64,16 @@ export default class ApiService {
73
64
  const response = await this.refresh()
74
65
 
75
66
  const newToken = response.accessToken
76
-
77
67
  if (!newToken) {
78
68
  this.logoutUser()
79
69
  return Promise.reject(error)
80
70
  }
81
71
 
82
72
  this.setAccessToken(newToken)
83
-
84
73
  this.onRefreshed(newToken)
85
74
  this.isRefreshing = false
86
-
87
- originalRequest.headers['Authorization'] = `Bearer ${newToken}`
88
75
  return this.axiosInstance(originalRequest)
89
76
  } catch (e) {
90
- this.isRefreshing = false
91
77
  this.logoutUser()
92
78
  return Promise.reject(e)
93
79
  }
@@ -120,6 +106,7 @@ export default class ApiService {
120
106
  }
121
107
 
122
108
  public logoutUser(): any {
109
+ this.isRefreshing = false
123
110
  this.post<any, any>(`/v2/logout`, {})
124
111
  this.removeToken()
125
112
  window.location.href = '/sign-in'