This commit is contained in:
fengchuanhn@gmail.com
2026-05-22 14:52:30 +08:00
parent ce1fe99883
commit ca1b254825
2 changed files with 32 additions and 5 deletions

View File

@@ -1,5 +1,6 @@
import { createApp } from "vue";
import { createPinia } from "pinia";
import { listen } from "@tauri-apps/api/event";
import PrimeVue from "primevue/config";
import { AiclientPreset } from "./theme/aiclient-preset.js";
import Button from "primevue/button";
@@ -71,6 +72,29 @@ app.component("DataTable", DataTable);
app.component("Column", Column);
app.component("Tag", Tag);
useAuthStore(pinia).hydrateRustSession();
const authStore = useAuthStore(pinia);
authStore.hydrateRustSession();
function setupHeartbeatLogoutListener() {
if (typeof window === "undefined" || !("__TAURI_INTERNALS__" in window)) {
return;
}
listen("auth-heartbeat-failed", async (event) => {
const message =
typeof event.payload === "string"
? event.payload
: event.payload?.message ?? "会话已失效";
console.warn("[heartbeat] failed:", message);
if (!authStore.isAuthenticated) {
return;
}
await authStore.logout();
if (router.currentRoute.value.name !== "login") {
await router.replace({ name: "login" });
}
});
}
setupHeartbeatLogoutListener();
app.mount("#app");