shared-ritm 1.3.43 → 1.3.44
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,11 +4,12 @@ export declare enum ApiServiceType {
|
|
|
4
4
|
}
|
|
5
5
|
export default class ApiService {
|
|
6
6
|
private axiosInstance;
|
|
7
|
+
private isRefresh;
|
|
7
8
|
constructor();
|
|
8
9
|
private getToken;
|
|
9
10
|
private removeToken;
|
|
10
11
|
private refresh;
|
|
11
|
-
|
|
12
|
+
logoutUser(): any;
|
|
12
13
|
private handleError;
|
|
13
14
|
protected get<T>(url: string, options?: AxiosRequestConfig): Promise<T>;
|
|
14
15
|
protected delete<T>(url: string, options?: AxiosRequestConfig): Promise<AxiosResponse<T, any, {}>>;
|
package/package.json
CHANGED
|
@@ -2,7 +2,7 @@ import axios, { AxiosError, AxiosInstance, AxiosRequestConfig, AxiosResponse, In
|
|
|
2
2
|
import { Api_Auth_Login } from '@/api/types/Api_Auth'
|
|
3
3
|
|
|
4
4
|
interface Api_Auth_Refresh {
|
|
5
|
-
|
|
5
|
+
accessToken: string
|
|
6
6
|
}
|
|
7
7
|
|
|
8
8
|
export enum ApiServiceType {
|
|
@@ -12,6 +12,8 @@ export enum ApiServiceType {
|
|
|
12
12
|
export default class ApiService {
|
|
13
13
|
private axiosInstance: AxiosInstance
|
|
14
14
|
|
|
15
|
+
private isRefresh = false
|
|
16
|
+
|
|
15
17
|
constructor() {
|
|
16
18
|
this.axiosInstance = axios.create({
|
|
17
19
|
baseURL: process.env.VUE_APP_BACKEND,
|
|
@@ -39,10 +41,24 @@ export default class ApiService {
|
|
|
39
41
|
(response: AxiosResponse) => {
|
|
40
42
|
return response.data
|
|
41
43
|
},
|
|
42
|
-
(error: AxiosError) => {
|
|
44
|
+
async (error: AxiosError) => {
|
|
43
45
|
if (error.response?.status === 401 || error.response?.status === 403) {
|
|
44
|
-
this.
|
|
45
|
-
|
|
46
|
+
if (!!this.getToken() && !this.isRefresh) {
|
|
47
|
+
this.isRefresh = true
|
|
48
|
+
return this.refresh().then(response => {
|
|
49
|
+
if (!response?.accessToken) {
|
|
50
|
+
alert('logout')
|
|
51
|
+
console.log(response)
|
|
52
|
+
return this.logoutUser()
|
|
53
|
+
}
|
|
54
|
+
if (response?.accessToken) {
|
|
55
|
+
console.log(response)
|
|
56
|
+
alert('da')
|
|
57
|
+
return true
|
|
58
|
+
}
|
|
59
|
+
})
|
|
60
|
+
}
|
|
61
|
+
return this.logoutUser()
|
|
46
62
|
}
|
|
47
63
|
return Promise.reject(error)
|
|
48
64
|
},
|
|
@@ -57,16 +73,15 @@ export default class ApiService {
|
|
|
57
73
|
localStorage.removeItem('token')
|
|
58
74
|
}
|
|
59
75
|
|
|
60
|
-
private
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
console.log(data)
|
|
64
|
-
return {} as any
|
|
76
|
+
private refresh(): Promise<Api_Auth_Refresh> {
|
|
77
|
+
return this.post<null, Api_Auth_Login>(`/v2/auth/refresh`, null)
|
|
65
78
|
}
|
|
66
79
|
|
|
67
|
-
public
|
|
80
|
+
public logoutUser(): any {
|
|
81
|
+
this.post<null, any>(`/v2/logout`, null)
|
|
68
82
|
this.removeToken()
|
|
69
83
|
window.location.href = '/sign-in'
|
|
84
|
+
return {} as any
|
|
70
85
|
}
|
|
71
86
|
|
|
72
87
|
private handleError(error: AxiosError): void {
|