@truedat/core 4.48.11 → 4.48.14
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/CHANGELOG.md +6 -0
- package/package.json +2 -2
- package/src/services/axios.js +22 -9
package/CHANGELOG.md
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@truedat/core",
|
|
3
|
-
"version": "4.48.
|
|
3
|
+
"version": "4.48.14",
|
|
4
4
|
"description": "Truedat Web Core",
|
|
5
5
|
"sideEffects": false,
|
|
6
6
|
"jsnext:main": "src/index.js",
|
|
@@ -112,5 +112,5 @@
|
|
|
112
112
|
"react-dom": ">= 16.8.6 < 17",
|
|
113
113
|
"semantic-ui-react": ">= 0.88.2 < 2.1"
|
|
114
114
|
},
|
|
115
|
-
"gitHead": "
|
|
115
|
+
"gitHead": "958a84bddc4a739679ea01e0758b78fa6583e240"
|
|
116
116
|
}
|
package/src/services/axios.js
CHANGED
|
@@ -1,22 +1,35 @@
|
|
|
1
|
+
import _ from "lodash/fp";
|
|
1
2
|
import axios from "axios";
|
|
2
|
-
import { readToken } from "./storage";
|
|
3
|
+
import { clearToken, readToken } from "./storage";
|
|
3
4
|
|
|
4
|
-
|
|
5
|
-
|
|
5
|
+
// If no authorization header is present and token exists in local storage, put
|
|
6
|
+
// the bearer token authorization header
|
|
7
|
+
const maybePutAuthorization = (config) => {
|
|
8
|
+
if (config.headers?.authorization) {
|
|
9
|
+
return config;
|
|
10
|
+
} else {
|
|
6
11
|
const token = readToken();
|
|
7
12
|
return token === null
|
|
8
|
-
?
|
|
13
|
+
? token
|
|
9
14
|
: {
|
|
10
15
|
...config,
|
|
11
16
|
headers: {
|
|
12
17
|
...config.headers,
|
|
13
|
-
|
|
18
|
+
authorization: `Bearer ${token}`,
|
|
14
19
|
},
|
|
15
20
|
};
|
|
16
|
-
},
|
|
17
|
-
function (err) {
|
|
18
|
-
return Promise.reject(err);
|
|
19
21
|
}
|
|
20
|
-
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
// If an unauthorized response is received, remove token from local storage
|
|
25
|
+
const maybeClearToken = (error) => {
|
|
26
|
+
if (error?.response?.status === 401) {
|
|
27
|
+
clearToken();
|
|
28
|
+
}
|
|
29
|
+
return Promise.reject(error);
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
axios.interceptors.request.use(maybePutAuthorization, Promise.reject);
|
|
33
|
+
axios.interceptors.response.use(_.identity, maybeClearToken);
|
|
21
34
|
|
|
22
35
|
export default axios;
|