refactor : merge Inventory_frontend submodule into frontend/ directory
Merges the full git history of Inventory_frontend into the monorepo under frontend/. Removes the submodule in favor of a unified repo. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
33
frontend/app/middleware/profile.global.ts
Normal file
33
frontend/app/middleware/profile.global.ts
Normal file
@@ -0,0 +1,33 @@
|
||||
import { useProfileSession, usePermissions } from "#imports";
|
||||
|
||||
export default defineNuxtRouteMiddleware(async (to) => {
|
||||
const { ensureSession, activeProfile } = useProfileSession();
|
||||
await ensureSession();
|
||||
|
||||
const rawPath = to?.path ?? "";
|
||||
const normalizedPath = rawPath.startsWith("/") ? rawPath : `/${rawPath}`;
|
||||
const fullPath = to?.fullPath ?? normalizedPath;
|
||||
const routeName = typeof to?.name === "string" ? to.name : "";
|
||||
const isProfilesRoute =
|
||||
normalizedPath.startsWith("/profiles") ||
|
||||
fullPath.startsWith("/profiles") ||
|
||||
routeName.startsWith("profiles");
|
||||
|
||||
// Redirect to login if no active profile
|
||||
if (!activeProfile.value && !isProfilesRoute) {
|
||||
return navigateTo("/profiles");
|
||||
}
|
||||
|
||||
// Permission checks
|
||||
if (activeProfile.value) {
|
||||
const { isAdmin } = usePermissions();
|
||||
|
||||
// Admin-only routes
|
||||
if (normalizedPath.startsWith("/admin")) {
|
||||
if (!isAdmin.value) {
|
||||
return navigateTo("/");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
});
|
||||
Reference in New Issue
Block a user