tsv2-library 0.2.46 → 0.2.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.
- package/dist/src/build-entry.d.ts +2 -2
- package/dist/src/services/auth.service.d.ts +8 -0
- package/dist/src/types/user.type.d.ts +89 -0
- package/dist/src/utils/clearStorage.util.d.ts +2 -0
- package/dist/src/utils/forceLogout.util.d.ts +2 -0
- package/dist/src/utils/index.d.ts +4 -1
- package/dist/src/utils/reLogin.util.d.ts +2 -0
- package/dist/tsv2-library.es.js +6815 -6777
- package/package.json +1 -1
- package/src/services/auth.service.ts +47 -0
package/package.json
CHANGED
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
/* eslint-disable promise/prefer-await-to-callbacks */
|
|
2
|
+
import axios, { AxiosError, AxiosInstance, AxiosResponse } from 'axios';
|
|
3
|
+
import forceLogout from '@/utils/forceLogout.util';
|
|
4
|
+
|
|
5
|
+
type ResponseData = {
|
|
6
|
+
message: string;
|
|
7
|
+
statusCode: number;
|
|
8
|
+
};
|
|
9
|
+
|
|
10
|
+
const api = ({ headers = {}, params = {} } = {}): AxiosInstance => {
|
|
11
|
+
const BASE_URL = import.meta.env.VITE_APP_USERS_V2_API;
|
|
12
|
+
|
|
13
|
+
const instance = axios.create({
|
|
14
|
+
baseURL: `${BASE_URL}/v2/auth`,
|
|
15
|
+
headers: {
|
|
16
|
+
'Content-type': 'application/json',
|
|
17
|
+
...headers,
|
|
18
|
+
},
|
|
19
|
+
params,
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
instance.interceptors.response.use(
|
|
23
|
+
(response: AxiosResponse) => {
|
|
24
|
+
return response;
|
|
25
|
+
},
|
|
26
|
+
(error: AxiosError) => {
|
|
27
|
+
if (
|
|
28
|
+
error.response?.status === 401 ||
|
|
29
|
+
(error.response?.data as ResponseData).message === 'jwt malformed'
|
|
30
|
+
) {
|
|
31
|
+
forceLogout();
|
|
32
|
+
}
|
|
33
|
+
return Promise.reject(error);
|
|
34
|
+
},
|
|
35
|
+
);
|
|
36
|
+
|
|
37
|
+
return instance;
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
type ReLogin = { jwt: string };
|
|
41
|
+
const reLogin = (body: ReLogin): Promise<AxiosResponse> => {
|
|
42
|
+
return api().post('/login', body);
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
const AuthAPIs = { reLogin };
|
|
46
|
+
|
|
47
|
+
export default AuthAPIs;
|