shared-ritm 1.3.42 → 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.
@@ -2,7 +2,6 @@ import ApiService from '../settings/ApiService';
2
2
  import { Api_Auth_Login, ChangePasswordResponse, ConfigResponse } from '@/api/types/Api_Auth';
3
3
  declare class AuthService extends ApiService {
4
4
  login(email: string, password: string): Promise<Api_Auth_Login>;
5
- refresh(email: string, password: string): Promise<Api_Auth_Login>;
6
5
  loginPhoto(photo: any): Promise<Api_Auth_Login>;
7
6
  loginVideo(data: any): Promise<Api_Auth_Login>;
8
7
  logout(): Promise<Api_Auth_Login>;
@@ -4,10 +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
- logout(): void;
11
+ private refresh;
12
+ logoutUser(): any;
11
13
  private handleError;
12
14
  protected get<T>(url: string, options?: AxiosRequestConfig): Promise<T>;
13
15
  protected delete<T>(url: string, options?: AxiosRequestConfig): Promise<AxiosResponse<T, any, {}>>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "shared-ritm",
3
- "version": "1.3.42",
3
+ "version": "1.3.44",
4
4
  "private": false,
5
5
  "files": [
6
6
  "dist",
@@ -15,13 +15,6 @@ class AuthService extends ApiService {
15
15
  })
16
16
  }
17
17
 
18
- public refresh(email: string, password: string): Promise<Api_Auth_Login> {
19
- return this.post<LoginPayload, Api_Auth_Login>(`/v2/auth/refresh`, {
20
- email,
21
- password,
22
- })
23
- }
24
-
25
18
  public loginPhoto(photo: any): Promise<Api_Auth_Login> {
26
19
  return this.post<any, Api_Auth_Login>(`/login/from_photo`, { photo })
27
20
  }
@@ -33,7 +26,7 @@ class AuthService extends ApiService {
33
26
  }
34
27
 
35
28
  public logout(): Promise<Api_Auth_Login> {
36
- return this.post<null, Api_Auth_Login>(`/v2/logout`, null)
29
+ return this.logoutUser()
37
30
  }
38
31
 
39
32
  public userInfo() {
@@ -1,4 +1,9 @@
1
1
  import axios, { AxiosError, AxiosInstance, AxiosRequestConfig, AxiosResponse, InternalAxiosRequestConfig } from 'axios'
2
+ import { Api_Auth_Login } from '@/api/types/Api_Auth'
3
+
4
+ interface Api_Auth_Refresh {
5
+ accessToken: string
6
+ }
2
7
 
3
8
  export enum ApiServiceType {
4
9
  SERVICE_AUTH = 'SERVICE_AUTH',
@@ -7,6 +12,8 @@ export enum ApiServiceType {
7
12
  export default class ApiService {
8
13
  private axiosInstance: AxiosInstance
9
14
 
15
+ private isRefresh = false
16
+
10
17
  constructor() {
11
18
  this.axiosInstance = axios.create({
12
19
  baseURL: process.env.VUE_APP_BACKEND,
@@ -34,9 +41,24 @@ export default class ApiService {
34
41
  (response: AxiosResponse) => {
35
42
  return response.data
36
43
  },
37
- (error: AxiosError) => {
44
+ async (error: AxiosError) => {
38
45
  if (error.response?.status === 401 || error.response?.status === 403) {
39
- this.logout()
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()
40
62
  }
41
63
  return Promise.reject(error)
42
64
  },
@@ -51,9 +73,15 @@ export default class ApiService {
51
73
  localStorage.removeItem('token')
52
74
  }
53
75
 
54
- public logout(): void {
76
+ private refresh(): Promise<Api_Auth_Refresh> {
77
+ return this.post<null, Api_Auth_Login>(`/v2/auth/refresh`, null)
78
+ }
79
+
80
+ public logoutUser(): any {
81
+ this.post<null, any>(`/v2/logout`, null)
55
82
  this.removeToken()
56
83
  window.location.href = '/sign-in'
84
+ return {} as any
57
85
  }
58
86
 
59
87
  private handleError(error: AxiosError): void {