54 lines
1.7 KiB
JavaScript
54 lines
1.7 KiB
JavaScript
import { executeAsync } from "/app/node_modules/unctx/dist/index.mjs";
|
|
import { j as defineNuxtRouteMiddleware, d as useCookie, n as navigateTo, c as useAuthStore } from "../server.mjs";
|
|
import "vue";
|
|
import "/app/node_modules/ofetch/dist/node.mjs";
|
|
import "#internal/nuxt/paths";
|
|
import "/app/node_modules/hookable/dist/index.mjs";
|
|
import "/app/node_modules/h3/dist/index.mjs";
|
|
import "pinia";
|
|
import "/app/node_modules/defu/dist/defu.mjs";
|
|
import "vue-router";
|
|
import "/app/node_modules/ufo/dist/index.mjs";
|
|
import "/app/node_modules/klona/dist/index.mjs";
|
|
import "/app/node_modules/cookie-es/dist/index.mjs";
|
|
import "/app/node_modules/destr/dist/index.mjs";
|
|
import "/app/node_modules/ohash/dist/index.mjs";
|
|
import "/app/node_modules/@unhead/vue/dist/index.mjs";
|
|
import "@vue/devtools-api";
|
|
import "vue/server-renderer";
|
|
const auth = defineNuxtRouteMiddleware(async (to, from) => {
|
|
let __temp, __restore;
|
|
if (to.path === "/login") {
|
|
return;
|
|
}
|
|
const tokenCookie = useCookie("access_token");
|
|
if (!tokenCookie.value) {
|
|
return navigateTo("/login");
|
|
}
|
|
const authStore = useAuthStore();
|
|
if (!authStore.user) {
|
|
try {
|
|
;
|
|
[__temp, __restore] = executeAsync(() => authStore.fetchUser()), await __temp, __restore();
|
|
;
|
|
} catch {
|
|
authStore.logout();
|
|
return navigateTo("/login");
|
|
}
|
|
}
|
|
if (!authStore.user) {
|
|
authStore.logout();
|
|
return navigateTo("/login");
|
|
}
|
|
const allowedRoles = ["SUPERADMIN", "ADMIN", "MODERATOR", "SALES_REP", "SERVICE_MGR"];
|
|
const userRole = (authStore.user.role || "").toUpperCase();
|
|
if (!allowedRoles.includes(userRole)) {
|
|
authStore.logout();
|
|
return navigateTo("/login");
|
|
}
|
|
});
|
|
export {
|
|
auth as default
|
|
};
|
|
//# sourceMappingURL=auth-nNLBs3fT.js.map
|