nidus-sync/ts/router.ts

171 lines
4.7 KiB
TypeScript
Raw Normal View History

import { createRouter, createWebHistory } from "vue-router";
import type { RouteRecordRaw } from "vue-router";
import Home from "./view/Home.vue";
import About from "./view/About.vue";
import Communication from "./view/Communication.vue";
2026-03-22 17:44:59 +00:00
import ConfigurationIntegration from "./view/configuration/Integration.vue";
2026-03-22 17:49:59 +00:00
import ConfigurationIntegrationArcgis from "./view/configuration/IntegrationArcgis.vue";
import ConfigurationOrganization from "./view/configuration/Organization.vue";
2026-03-22 17:25:11 +00:00
import ConfigurationPesticide from "./view/configuration/Pesticide.vue";
import ConfigurationPesticideAdd from "./view/configuration/PesticideAdd.vue";
2026-03-22 17:20:46 +00:00
import ConfigurationRoot from "./view/configuration/Root.vue";
2026-03-24 13:45:37 -07:00
import ConfigurationUpload from "./view/configuration/Upload.vue";
2026-03-22 17:20:46 +00:00
import ConfigurationUser from "./view/configuration/User.vue";
import ConfigurationUserAdd from "./view/configuration/UserAdd.vue";
2026-03-21 22:41:47 +00:00
import Intelligence from "./view/Intelligence.vue";
2026-03-23 14:24:24 -07:00
import NotFound from "./view/NotFound.vue";
2026-03-22 18:00:30 +00:00
import OAuthRefreshArcgis from "./view/OAuthRefreshArcgis.vue";
import Operations from "./view/Operations.vue";
import Planning from "./view/Planning.vue";
import Review from "./view/Review.vue";
2026-03-23 14:24:24 -07:00
import Signin from "./view/Signin.vue";
import Sudo from "./view/Sudo.vue";
2026-03-23 14:39:57 -07:00
import apiClient from "@/client";
const routes: RouteRecordRaw[] = [
{
path: "/",
name: "Home",
component: Home,
2026-03-23 14:24:24 -07:00
meta: { requiresAuth: true, showSidebar: true },
},
{
path: "/communication",
name: "Communication",
component: Communication,
2026-03-23 14:24:24 -07:00
meta: { requiresAuth: true, showSidebar: true },
},
{
path: "/configuration",
name: "Configuration",
2026-03-22 17:20:46 +00:00
component: ConfigurationRoot,
2026-03-23 14:24:24 -07:00
meta: { requiresAuth: true, showSidebar: true },
2026-03-22 17:20:46 +00:00
},
2026-03-22 17:44:59 +00:00
{
path: "/configuration/integration",
name: "Integration Configuration",
component: ConfigurationIntegration,
2026-03-23 14:24:24 -07:00
meta: { requiresAuth: true, showSidebar: true },
2026-03-22 17:44:59 +00:00
},
2026-03-22 17:49:59 +00:00
{
path: "/configuration/integration/arcgis",
name: "Arcgis Integration Configuration",
component: ConfigurationIntegrationArcgis,
2026-03-23 14:24:24 -07:00
meta: { requiresAuth: true, showSidebar: true },
2026-03-22 17:49:59 +00:00
},
{
path: "/configuration/organization",
name: "Organization Configuration",
component: ConfigurationOrganization,
2026-03-23 14:24:24 -07:00
meta: { requiresAuth: true, showSidebar: true },
},
2026-03-22 17:25:11 +00:00
{
path: "/configuration/pesticide",
name: "Pesticide Configuration",
component: ConfigurationPesticide,
2026-03-23 14:24:24 -07:00
meta: { requiresAuth: true, showSidebar: true },
2026-03-22 17:25:11 +00:00
},
{
path: "/configuration/pesticide/add",
name: "Pesticide Add",
component: ConfigurationPesticideAdd,
2026-03-23 14:24:24 -07:00
meta: { requiresAuth: true, showSidebar: true },
2026-03-24 13:45:37 -07:00
},
{
path: "/configuration/upload",
name: "Upload Configuration",
component: ConfigurationUpload,
meta: { requiresAuth: true, showSidebar: true },
},
2026-03-22 17:20:46 +00:00
{
path: "/configuration/user",
name: "User Configuration",
component: ConfigurationUser,
2026-03-23 14:24:24 -07:00
meta: { requiresAuth: true, showSidebar: true },
2026-03-22 17:20:46 +00:00
},
{
path: "/configuration/user/add",
name: "User Add Configuration",
component: ConfigurationUserAdd,
2026-03-23 14:24:24 -07:00
meta: { requiresAuth: true, showSidebar: true },
},
2026-03-21 22:41:47 +00:00
{
path: "/intelligence",
name: "Intelligence",
component: Intelligence,
2026-03-23 14:24:24 -07:00
meta: { requiresAuth: true, showSidebar: true },
2026-03-21 22:41:47 +00:00
},
2026-03-22 18:00:30 +00:00
{
path: "/oauth/refresh/arcgis",
name: "Arcgis OAuth Refresh",
component: OAuthRefreshArcgis,
2026-03-23 14:24:24 -07:00
meta: { requiresAuth: true, showSidebar: true },
2026-03-22 18:00:30 +00:00
},
{
path: "/operations",
name: "Operations",
component: Operations,
2026-03-23 14:24:24 -07:00
meta: { requiresAuth: true, showSidebar: true },
},
{
path: "/planning",
name: "Planning",
component: Planning,
2026-03-23 14:24:24 -07:00
meta: { requiresAuth: true, showSidebar: true },
},
{
path: "/review",
name: "Review",
component: Review,
2026-03-23 14:24:24 -07:00
meta: { requiresAuth: true, showSidebar: true },
},
{
path: "/signin",
name: "Signin",
component: Signin,
meta: { requiresAuth: false, showSidebar: false },
},
{
path: "/sudo",
name: "Sudo",
component: Sudo,
2026-03-23 14:24:24 -07:00
meta: { requiresAuth: true, showSidebar: true },
},
// Catch-all route - must be last
{
path: '/:pathMatch(.*)*',
name: 'NotFound',
component: NotFound
}
];
const router = createRouter({
history: createWebHistory("/"),
routes,
});
2026-03-23 14:39:57 -07:00
2026-03-23 14:24:24 -07:00
// Global navigation guard
router.beforeEach(async (to, from, next) => {
const requiresAuth = to.matched.some(record => record.meta.requiresAuth);
if (requiresAuth) {
try {
// Check if user is authenticated (could be an API call)
2026-03-23 14:39:57 -07:00
const isAuthenticated = await apiClient.isAuthenticated();
2026-03-23 14:24:24 -07:00
if (!isAuthenticated) {
next('/signin');
} else {
next();
}
} catch (error) {
console.log("check auth failed");
next('/signin');
}
} else {
next();
}
});
export default router;