This commit is contained in:
parent
37fd88bacf
commit
9fb3c51192
@ -3,7 +3,7 @@ import {RouterView, useRoute} from 'vue-router'
|
||||
import HomeHeader from '@/views/components/HomeHeader/HomeHeader.vue'
|
||||
import HomeAside from '@/views/components/HomeAside/HomeAside.vue';
|
||||
import RecoverySetupPrompt from '@/views/components/RecoverySetupPrompt/RecoverySetupPrompt.vue'
|
||||
import {ref, watch, onMounted} from 'vue'
|
||||
import {ref, watch} from 'vue'
|
||||
import {useGlobalStatusStore} from "@/stores/useGlobalStatusStore";
|
||||
|
||||
const route = useRoute()
|
||||
@ -11,12 +11,6 @@ const pageName = ref(route.name)
|
||||
const globalStatus = useGlobalStatusStore();
|
||||
const standalonePages = ['login', 'login-verification', 'force-password-change', 'setup', 'forgot-password', 'reset-blocked']
|
||||
|
||||
onMounted(() => {
|
||||
if (!standalonePages.includes(route.name)) {
|
||||
globalStatus.init(() => {});
|
||||
}
|
||||
});
|
||||
|
||||
watch(
|
||||
() => route.fullPath,
|
||||
() => {
|
||||
|
||||
@ -29,7 +29,12 @@ if (isReservedResetPath(window.location.pathname)) {
|
||||
}
|
||||
|
||||
const app = createApp(App)
|
||||
const pinia = createPinia()
|
||||
|
||||
app.use(pinia)
|
||||
app.use(router)
|
||||
app.use(createPinia())
|
||||
app.use(ElementPlus)
|
||||
app.mount('#app')
|
||||
app.use(ElementPlus)
|
||||
|
||||
router.isReady().then(() => {
|
||||
app.mount('#app')
|
||||
})
|
||||
|
||||
@ -1,6 +1,8 @@
|
||||
import { defineStore } from "pinia";
|
||||
import { http } from "@/utils/axios";
|
||||
|
||||
let authRefreshPromise = null;
|
||||
|
||||
const useGlobalStatusStore = defineStore("useGlobalStatusStore", {
|
||||
state() {
|
||||
return {
|
||||
@ -27,33 +29,39 @@ const useGlobalStatusStore = defineStore("useGlobalStatusStore", {
|
||||
}
|
||||
},
|
||||
actions: {
|
||||
async refresh() {
|
||||
if (this.authLoading) {
|
||||
return this.isLogin;
|
||||
refresh() {
|
||||
if (authRefreshPromise) {
|
||||
return authRefreshPromise;
|
||||
}
|
||||
|
||||
this.authLoading = true;
|
||||
try {
|
||||
const response = await http.post("/api/v1/user/info", {});
|
||||
if (response.errorNo === 0 && response.data) {
|
||||
this.setUser(response.data, false);
|
||||
this.authChecked = true;
|
||||
return true;
|
||||
authRefreshPromise = (async () => {
|
||||
try {
|
||||
const response = await http.post("/api/v1/user/info", {});
|
||||
if (response.errorNo === 0 && response.data) {
|
||||
this.setUser(response.data, false);
|
||||
this.authChecked = true;
|
||||
return true;
|
||||
}
|
||||
this.clear();
|
||||
return false;
|
||||
} catch (error) {
|
||||
this.clear();
|
||||
return false;
|
||||
} finally {
|
||||
this.authLoading = false;
|
||||
authRefreshPromise = null;
|
||||
}
|
||||
this.clear();
|
||||
return false;
|
||||
} catch (error) {
|
||||
this.clear();
|
||||
return false;
|
||||
} finally {
|
||||
this.authLoading = false;
|
||||
}
|
||||
})();
|
||||
|
||||
return authRefreshPromise;
|
||||
},
|
||||
init(callback) {
|
||||
this.refresh().then(() => {
|
||||
return this.refresh().then((authenticated) => {
|
||||
if (typeof callback === "function") {
|
||||
callback();
|
||||
callback(authenticated);
|
||||
}
|
||||
return authenticated;
|
||||
});
|
||||
},
|
||||
clear() {
|
||||
|
||||
@ -63,7 +63,7 @@ http.interceptors.response.use(async (response) => {
|
||||
await router.replace({
|
||||
path: '/login',
|
||||
query: {
|
||||
redirect: router.currentRoute.fullPath
|
||||
redirect: router.currentRoute.value.fullPath
|
||||
}
|
||||
});
|
||||
}
|
||||
@ -72,7 +72,7 @@ http.interceptors.response.use(async (response) => {
|
||||
await router.replace({
|
||||
path: '/setup',
|
||||
query: {
|
||||
redirect: router.currentRoute.fullPath
|
||||
redirect: router.currentRoute.value.fullPath
|
||||
}
|
||||
});
|
||||
}
|
||||
@ -95,7 +95,7 @@ http.interceptors.response.use(async (response) => {
|
||||
await router.replace({
|
||||
path: '/login',
|
||||
query: {
|
||||
redirect: router.currentRoute.fullPath
|
||||
redirect: router.currentRoute.value.fullPath
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user