merca y ch

This commit is contained in:
Marcelo
2026-03-31 13:21:48 +00:00
commit 773bfab393
326 changed files with 52705 additions and 0 deletions

42
middleware.ts Normal file
View File

@@ -0,0 +1,42 @@
import { withAuth } from "next-auth/middleware";
import { NextResponse } from "next/server";
import { canAccessPath, getDepartmentHomeRoute } from "@/lib/access-control";
import type { DepartmentKey, UserRole } from "@/lib/types";
export default withAuth(
function middleware(req) {
const token = req.nextauth.token;
const role = token?.role as UserRole | undefined;
const department = (token?.department as DepartmentKey | null | undefined) ?? null;
const pathname = req.nextUrl.pathname;
if (!canAccessPath({ role, department }, pathname)) {
const fallbackPath = role === "owner" ? "/dashboard" : getDepartmentHomeRoute(department);
const safeFallbackPath = pathname === fallbackPath ? "/settings" : fallbackPath;
return NextResponse.redirect(new URL(safeFallbackPath, req.url));
}
return NextResponse.next();
},
{
pages: {
signIn: "/login",
},
}
);
export const config = {
matcher: [
"/dashboard/:path*",
"/financial-flow/:path*",
"/experienciometro/:path*",
"/departments/:path*",
"/initiatives/:path*",
"/meetings/:path*",
"/people/:path*",
"/data-entry/:path*",
"/settings/:path*",
"/api/invitations",
"/api/experienciometro/:path*",
],
};