1
This commit is contained in:
26
src/main.js
26
src/main.js
@@ -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");
|
||||
|
||||
Reference in New Issue
Block a user