Skip to content

Commit

Permalink
perf: replace 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 e40c3a1 commit 87a58ae
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
2 changes: 1 addition & 1 deletion src/components/AppHeader.vue
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,7 @@ export default {
},
async created() {
document.addEventListener('click', this.handleDocumentClick);
this.profile = await this.$profile();
this.profile = this.$profile();
},
methods: {
openMenu(item) {
Expand Down
12 changes: 6 additions & 6 deletions src/plugins/profile.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ const {
VUE_APP_SARA_TOKEN_NAME: saraTokenName,
} = process.env;

const getProfile = async () => {
export const useProfile = () => {
const saraToken = localStorage.getItem(saraTokenName);
if (!saraToken) {
return null;
Expand All @@ -18,7 +18,7 @@ const getProfile = async () => {
if (Date.now() >= data.exp * 1000) {
throw new Error("sara token expired");
}
return data?.user || false;
return data?.user;
} catch (e) {
console.warn(e);
localStorage.removeItem(saraTokenName);
Expand All @@ -29,10 +29,10 @@ const getProfile = async () => {

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

Expand Down

0 comments on commit 87a58ae

Please sign in to comment.