Skip to content

Commit

Permalink
Merge pull request #125 from web-tech-tw/zebra
Browse files Browse the repository at this point in the history
Implement Zebra Code
  • Loading branch information
supersonictw authored Oct 11, 2024
2 parents a71fed9 + 03c75cb commit 23a6adf
Show file tree
Hide file tree
Showing 4 changed files with 81 additions and 26 deletions.
6 changes: 4 additions & 2 deletions .env
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
VUE_APP_SELF_HOST=https://web-tech.tw/openchat
VUE_APP_OCJI_HOST=https://web-tech.tw/recv/openchat

VUE_APP_TURNSTILE_SITE_KEY="0x4AAAAAAAr6LY1hBUbTBkVA"

VUE_APP_SARA_INTE_HOST=https://web-tech.tw/sara
VUE_APP_SARA_RECV_HOST=https://web-tech.tw/recv/sara
VUE_APP_SARA_TOKEN_NAME=unified_token

VUE_APP_TURNSTILE_SITE_KEY="0x4AAAAAAAr6LY1hBUbTBkVA"

VUE_APP_ZEBRA_TOKEN_NAME="zebra"
86 changes: 63 additions & 23 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
"autoprefixer": "^10",
"core-js": "^3.8.3",
"dayjs": "^1.11.12",
"nanoid": "^5.0.7",
"postcss": "^8",
"tailwindcss": "^3",
"ua-parser-js": "^1.0.38",
Expand Down
14 changes: 13 additions & 1 deletion src/plugins/axios.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,14 @@
import Vue from "vue";
import axios from "axios";

import {
nanoid,
} from "nanoid";

const {
VUE_APP_OCJI_HOST: ocjiRecvHost,
VUE_APP_SARA_TOKEN_NAME: saraTokenName,
VUE_APP_ZEBRA_TOKEN_NAME: zebraTokenName,
} = process.env;

// Full config: https://github.com/axios/axios#request-config
Expand All @@ -22,12 +27,19 @@ const axiosClient = axios.create(config);
axiosClient.interceptors.request.use(
// Do something before request is sent
(config) => {
let zebraToken = localStorage.getItem(zebraTokenName);
if (!zebraToken) {
zebraToken = nanoid();
localStorage.setItem(zebraTokenName, zebraToken);
}
config.headers["X-Zebra-Code"] = zebraToken;

const saraToken = localStorage.getItem(saraTokenName);
if (!saraToken) {
return config
}

config.headers["Authorization"] = `SARA ${saraToken}`;

return config;
},
// Do something with request error
Expand Down

0 comments on commit 23a6adf

Please sign in to comment.