|
|
@@ -27,6 +27,24 @@ const router = createRouter({
|
|
|
},
|
|
|
});
|
|
|
|
|
|
+router.beforeEach(async (to) => {
|
|
|
+ const { useAuthStore } = await import("@/stores/auth");
|
|
|
+ const authStore = useAuthStore();
|
|
|
+
|
|
|
+ // Ensure we check auth state
|
|
|
+ if (!authStore.user && localStorage.getItem("token")) {
|
|
|
+ await authStore.init();
|
|
|
+ }
|
|
|
+
|
|
|
+ if (to.path === "/admin" && authStore.user?.role !== "admin") {
|
|
|
+ return { path: "/auth" };
|
|
|
+ }
|
|
|
+
|
|
|
+ if (to.path === "/orders" && !authStore.user) {
|
|
|
+ return { path: "/auth" };
|
|
|
+ }
|
|
|
+});
|
|
|
+
|
|
|
router.afterEach((to) => {
|
|
|
const baseTitle = "Radionica 3D";
|
|
|
const pageTitle = to.meta.title ? `${to.meta.title} | ${baseTitle}` : baseTitle;
|