Skip to content

Commit 936836c

Browse files
committed
feat: add zebra token
1 parent a71fed9 commit 936836c

File tree

3 files changed

+76
-23
lines changed

3 files changed

+76
-23
lines changed

package-lock.json

Lines changed: 63 additions & 23 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
"autoprefixer": "^10",
1313
"core-js": "^3.8.3",
1414
"dayjs": "^1.11.12",
15+
"nanoid": "^5.0.7",
1516
"postcss": "^8",
1617
"tailwindcss": "^3",
1718
"ua-parser-js": "^1.0.38",

src/plugins/axios.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,13 @@
33
import Vue from "vue";
44
import axios from "axios";
55

6+
import {
7+
nanoid,
8+
} from "nanoid";
9+
610
const {
711
VUE_APP_OCJI_HOST: ocjiRecvHost,
12+
VUE_APP_OCJI_ZEBRA_TOKEN_NAME: zebraTokenName,
813
VUE_APP_SARA_TOKEN_NAME: saraTokenName,
914
} = process.env;
1015

@@ -27,7 +32,14 @@ axiosClient.interceptors.request.use(
2732
return config
2833
}
2934

35+
let zebraToken = localStorage.getItem(zebraTokenName);
36+
if (!zebraToken) {
37+
zebraToken = nanoid();
38+
localStorage.setItem(zebraTokenName, zebraToken);
39+
}
40+
3041
config.headers["Authorization"] = `SARA ${saraToken}`;
42+
config.headers["X-OCJI-Zebra"] = zebraToken;
3143
return config;
3244
},
3345
// Do something with request error

0 commit comments

Comments
 (0)