24 lines
664 B
TypeScript
24 lines
664 B
TypeScript
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);
|
|
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");
|