Skip to content

Commit 23a6adf

Browse files
authored
Merge pull request #125 from web-tech-tw/zebra
Implement Zebra Code
2 parents a71fed9 + 03c75cb commit 23a6adf

File tree

4 files changed

+81
-26
lines changed

4 files changed

+81
-26
lines changed

.env

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
VUE_APP_SELF_HOST=https://web-tech.tw/openchat
22
VUE_APP_OCJI_HOST=https://web-tech.tw/recv/openchat
33

4-
VUE_APP_TURNSTILE_SITE_KEY="0x4AAAAAAAr6LY1hBUbTBkVA"
5-
64
VUE_APP_SARA_INTE_HOST=https://web-tech.tw/sara
75
VUE_APP_SARA_RECV_HOST=https://web-tech.tw/recv/sara
86
VUE_APP_SARA_TOKEN_NAME=unified_token
7+
8+
VUE_APP_TURNSTILE_SITE_KEY="0x4AAAAAAAr6LY1hBUbTBkVA"
9+
10+
VUE_APP_ZEBRA_TOKEN_NAME="zebra"

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: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,14 @@
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,
812
VUE_APP_SARA_TOKEN_NAME: saraTokenName,
13+
VUE_APP_ZEBRA_TOKEN_NAME: zebraTokenName,
914
} = process.env;
1015

1116
// Full config: https://github.com/axios/axios#request-config
@@ -22,12 +27,19 @@ const axiosClient = axios.create(config);
2227
axiosClient.interceptors.request.use(
2328
// Do something before request is sent
2429
(config) => {
30+
let zebraToken = localStorage.getItem(zebraTokenName);
31+
if (!zebraToken) {
32+
zebraToken = nanoid();
33+
localStorage.setItem(zebraTokenName, zebraToken);
34+
}
35+
config.headers["X-Zebra-Code"] = zebraToken;
36+
2537
const saraToken = localStorage.getItem(saraTokenName);
2638
if (!saraToken) {
2739
return config
2840
}
29-
3041
config.headers["Authorization"] = `SARA ${saraToken}`;
42+
3143
return config;
3244
},
3345
// Do something with request error

0 commit comments

Comments
 (0)