fix: 统一管理后台 401 与加载失败处理
This commit is contained in:
+15
-1
@@ -2,8 +2,22 @@ import { createApp } from "vue";
|
||||
import { createPinia } from "pinia";
|
||||
import App from "./App.vue";
|
||||
import { router } from "./router";
|
||||
import { setUnauthorizedHandler } from "./api/http";
|
||||
import { useAuthStore } from "./stores/auth";
|
||||
|
||||
const app = createApp(App);
|
||||
app.use(createPinia());
|
||||
const pinia = createPinia();
|
||||
app.use(pinia);
|
||||
app.use(router);
|
||||
|
||||
setUnauthorizedHandler((redirect) => {
|
||||
const auth = useAuthStore();
|
||||
auth.clearSession();
|
||||
if (router.currentRoute.value.meta.public) {
|
||||
return;
|
||||
}
|
||||
const target = redirect.startsWith("/login") ? "/overview" : redirect || "/overview";
|
||||
void router.replace({ name: "login", query: { redirect: target } });
|
||||
});
|
||||
|
||||
app.mount("#app");
|
||||
|
||||
Reference in New Issue
Block a user