shared-ritm 1.3.45 → 1.3.48

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.
@@ -8,6 +8,7 @@ declare class AuthService extends ApiService {
8
8
  userInfo(): Promise<any>;
9
9
  configs(): Promise<ConfigResponse>;
10
10
  changePassword(id: string, password: string, password_confirmation: string): Promise<ChangePasswordResponse>;
11
+ changePasswordAndActivate(email: string, currentPassword: string, password: string, passwordConfirmation: string): Promise<any>;
11
12
  }
12
13
  export default function useAuthService(): AuthService;
13
14
  export {};
@@ -6,8 +6,8 @@ export default class ApiService {
6
6
  private axiosInstance;
7
7
  private isRefresh;
8
8
  constructor();
9
- private setToken;
10
- private getToken;
9
+ private setAccessToken;
10
+ private getAccessToken;
11
11
  private removeToken;
12
12
  private refresh;
13
13
  logoutUser(): any;
@@ -73,5 +73,11 @@ export type ChangePasswordPayload = {
73
73
  password: string;
74
74
  password_confirmation: string;
75
75
  };
76
+ export type ChangePasswordAndActivatePayload = {
77
+ email: string;
78
+ currentPassword: string;
79
+ password: string;
80
+ passwordConfirmation: string;
81
+ };
76
82
  export type ChangePasswordResponse = Pick<Api_User, 'id' | 'archiveHistory' | 'assigned_tasks' | 'divisions' | 'email' | 'full_name' | 'passes' | 'personnel_number' | 'phone' | 'photos' | 'positions' | 'responsible_tasks' | 'teams' | 'warehouses'>;
77
83
  export type ConfigResponse = any;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "shared-ritm",
3
- "version": "1.3.45",
3
+ "version": "1.3.48",
4
4
  "private": false,
5
5
  "files": [
6
6
  "dist",
@@ -1,6 +1,7 @@
1
1
  import ApiService from '../settings/ApiService'
2
2
  import {
3
3
  Api_Auth_Login,
4
+ ChangePasswordAndActivatePayload,
4
5
  ChangePasswordPayload,
5
6
  ChangePasswordResponse,
6
7
  ConfigResponse,
@@ -43,6 +44,19 @@ class AuthService extends ApiService {
43
44
  password_confirmation,
44
45
  })
45
46
  }
47
+ public changePasswordAndActivate(
48
+ email: string,
49
+ currentPassword: string,
50
+ password: string,
51
+ passwordConfirmation: string,
52
+ ) {
53
+ return this.post<ChangePasswordAndActivatePayload, ChangePasswordResponse>(`/v2/auth/users/activate`, {
54
+ email,
55
+ currentPassword,
56
+ password,
57
+ passwordConfirmation,
58
+ })
59
+ }
46
60
  }
47
61
 
48
62
  let api: AuthService
@@ -26,9 +26,9 @@ export default class ApiService {
26
26
 
27
27
  this.axiosInstance.interceptors.request.use(
28
28
  (config: InternalAxiosRequestConfig) => {
29
- const token = this.getToken()
30
- if (token && config.headers) {
31
- config.headers.Authorization = `Bearer ${token}`
29
+ const access_token = this.getAccessToken()
30
+ if (access_token && config.headers) {
31
+ config.headers.Authorization = `Bearer ${access_token}`
32
32
  }
33
33
  return config
34
34
  },
@@ -41,16 +41,25 @@ export default class ApiService {
41
41
  (response: AxiosResponse) => {
42
42
  return response.data
43
43
  },
44
- async (error: AxiosError) => {
44
+ async error => {
45
+ const originalRequest = error.config
46
+
47
+ if (originalRequest?._retry) {
48
+ throw error
49
+ }
50
+
45
51
  if (error.response?.status === 401 || error.response?.status === 403) {
46
- if (!!this.getToken() && !this.isRefresh) {
52
+ if (!this.getAccessToken()) return Promise.reject(error)
53
+ if (!this.isRefresh) {
54
+ originalRequest._retry = true
47
55
  this.isRefresh = true
48
56
  return this.refresh().then(response => {
49
57
  if (!response?.accessToken) {
50
- return this.logoutUser()
58
+ this.logoutUser()
51
59
  }
52
60
  if (response?.accessToken) {
53
- return this.setToken(response.accessToken)
61
+ this.setAccessToken(response.accessToken)
62
+ this.axiosInstance(originalRequest)
54
63
  }
55
64
  })
56
65
  }
@@ -61,11 +70,10 @@ export default class ApiService {
61
70
  )
62
71
  }
63
72
 
64
- private setToken(token: string) {
73
+ private setAccessToken(token: string) {
65
74
  localStorage.setItem('token', token)
66
75
  }
67
-
68
- private getToken() {
76
+ private getAccessToken() {
69
77
  return localStorage.getItem('token')
70
78
  }
71
79
 
@@ -84,6 +84,13 @@ export type ChangePasswordPayload = {
84
84
  password_confirmation: string
85
85
  }
86
86
 
87
+ export type ChangePasswordAndActivatePayload = {
88
+ email: string
89
+ currentPassword: string
90
+ password: string
91
+ passwordConfirmation: string
92
+ }
93
+
87
94
  export type ChangePasswordResponse = Pick<
88
95
  Api_User,
89
96
  | 'id'