56 lines
1.5 KiB
JavaScript
56 lines
1.5 KiB
JavaScript
import { K as executeAsync } from '../nitro/nitro.mjs';
|
|
import { j as defineNuxtRouteMiddleware, d as useCookie, n as navigateTo, c as useAuthStore } from './server.mjs';
|
|
import 'node:http';
|
|
import 'node:https';
|
|
import 'node:events';
|
|
import 'node:buffer';
|
|
import 'node:fs';
|
|
import 'node:path';
|
|
import 'node:crypto';
|
|
import 'vue-router';
|
|
import 'node:url';
|
|
import 'vue';
|
|
import 'pinia';
|
|
import 'vue/server-renderer';
|
|
import '../routes/renderer.mjs';
|
|
import 'vue-bundle-renderer/runtime';
|
|
import 'unhead/server';
|
|
import 'devalue';
|
|
import 'unhead/utils';
|
|
import 'unhead/plugins';
|
|
|
|
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.mjs.map
|