Skip to content

Commit

Permalink
perf: remove sara with jwt decoder
Browse files Browse the repository at this point in the history
  • Loading branch information
supersonictw committed Oct 14, 2024
1 parent d6382d2 commit 4a2d700
Show file tree
Hide file tree
Showing 6 changed files with 89 additions and 106 deletions.
1 change: 0 additions & 1 deletion .env
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
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
60 changes: 45 additions & 15 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 @@ -11,6 +11,7 @@
"@tailwindcss/typography": "^0.5.2",
"autoprefixer": "^10",
"core-js": "^3.8.3",
"jwt-decode": "^4.0.0",
"postcss": "^8",
"tailwindcss": "^3",
"vue": "^2.7.16",
Expand Down
2 changes: 1 addition & 1 deletion src/main.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import Vue from 'vue'
import './plugins/sara'
import './plugins/axios'
import './plugins/profile'
import App from './App.vue'
import './assets/tailwind.css'
import router from './router'
Expand Down
42 changes: 42 additions & 0 deletions src/plugins/profile.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
"use strict";

import Vue from "vue";
import { jwtDecode } from "jwt-decode";

const {
VUE_APP_SARA_TOKEN_NAME: saraTokenName,
} = process.env;

const getProfile = async () => {
const saraToken = localStorage.getItem(saraTokenName);
if (!saraToken) {
return null;
}

try {
const data = jwtDecode(saraToken);
return data?.user || false;
} catch (e) {
if (e?.response?.status !== 401) {
console.warn(e);
return null;
}

localStorage.removeItem(saraTokenName);
location.reload();
return null;
}
};

const extension = {
install: (Vue) => {
window.profile = getProfile;
Vue.profile = getProfile;
Vue.prototype.profile = getProfile;
Vue.prototype.$profile = getProfile;
},
};

Vue.use(extension);

export default extension;
89 changes: 0 additions & 89 deletions src/plugins/sara.js

This file was deleted.

0 comments on commit 4a2d700

Please sign in to comment.