mirror of
https://github.com/hpd840321/craftlabs-authorization-sdk.git
synced 2026-06-09 10:00:30 +08:00
499fef3c2f
Made-with: Cursor
40 lines
1023 B
JavaScript
40 lines
1023 B
JavaScript
import { createApp } from "vue";
|
|
import { createPinia } from "pinia";
|
|
import ElementPlus from "element-plus";
|
|
import "element-plus/dist/index.css";
|
|
import axios from "axios";
|
|
import App from "./App.vue";
|
|
import router from "./router";
|
|
import { useAuthStore } from "./stores/auth";
|
|
|
|
const apiBase =
|
|
typeof import.meta.env.VITE_API_BASE === "string" ? import.meta.env.VITE_API_BASE.trim() : "";
|
|
if (apiBase) {
|
|
axios.defaults.baseURL = apiBase.replace(/\/+$/, "");
|
|
}
|
|
|
|
const pinia = createPinia();
|
|
const app = createApp(App);
|
|
app.use(pinia);
|
|
|
|
useAuthStore(pinia).restoreAxiosAuth();
|
|
|
|
axios.interceptors.response.use(
|
|
(r) => r,
|
|
(err) => {
|
|
if (err.response?.status === 401) {
|
|
const auth = useAuthStore();
|
|
auth.logout();
|
|
if (router.currentRoute.value.name !== "login") {
|
|
router.push({
|
|
name: "login",
|
|
query: { redirect: router.currentRoute.value.fullPath },
|
|
});
|
|
}
|
|
}
|
|
return Promise.reject(err);
|
|
},
|
|
);
|
|
|
|
app.use(router).use(ElementPlus).mount("#app");
|