Open-source manufacturing ERP, MES and QMS. Quoting, MRP, inventory, shop floor, quality and lot/serial traceability on one Postgres schema, with a REST API and MCP server. Self-host or use Carbon Cloud.
TypeScript ai-agentsbill-of-materialserpinventory-managementleanmanufacturingmanufacturing-execution-systemmcp-servermesmrpopen-source-erppostgresqlproduction-planningqmsquality-management-systemreact-routerself-hostedsupabasetraceabilitytypescript
fix: redirect to root on company change
Brad Barbinf72bf0e9748b
diff --git a/apps/mes/app/routes/x+/_layout.tsx b/apps/mes/app/routes/x+/_layout.tsxindex 076270babf..545d7771ff 100644--- a/apps/mes/app/routes/x+/_layout.tsx+++ b/apps/mes/app/routes/x+/_layout.tsx@@ -28,6 +28,7 @@ import {getLocationsByCompany,} from "~/services/jobs.service";import {+ clearLocationAndWorkCenter,getLocationAndWorkCenter,setLocationAndWorkCenter,} from "~/services/location.server";@@ -84,7 +85,7 @@ export async function loader({ request }: LoaderFunctionArgs) {if (!locations.data.some((l) => l.id === storedLocations.location)) {throw redirect(path.to.authenticatedRoot, {headers: {- "Set-Cookie": setLocationAndWorkCenter("", ""),+ "Set-Cookie": clearLocationAndWorkCenter(),},});}diff --git a/apps/mes/app/routes/x+/company.switch.$companyId.tsx b/apps/mes/app/routes/x+/company.switch.$companyId.tsxindex 800b858d9f..5f5f0c2093 100644--- a/apps/mes/app/routes/x+/company.switch.$companyId.tsx+++ b/apps/mes/app/routes/x+/company.switch.$companyId.tsx@@ -6,7 +6,7 @@ import {updateCompanySession,} from "@carbon/auth/session.server";import { redirect, type ActionFunctionArgs } from "@vercel/remix";-import { setLocationAndWorkCenter } from "~/services/location.server";+import { clearLocationAndWorkCenter } from "~/services/location.server";import { path, requestReferrer } from "~/utils/path";export async function action({ request, params }: ActionFunctionArgs) {@@ -33,7 +33,7 @@ export async function action({ request, params }: ActionFunctionArgs) {}const sessionCookie = await updateCompanySession(request, companyId!);- const locationCookie = setLocationAndWorkCenter("", "");+ const locationCookie = clearLocationAndWorkCenter();throw redirect(requestReferrer(request) ?? path.to.authenticatedRoot, {headers: {diff --git a/apps/mes/app/routes/x+/jobs.$workCenterId.tsx b/apps/mes/app/routes/x+/jobs.$workCenterId.tsxindex 91ad1ee61b..7afcd7d7d6 100644--- a/apps/mes/app/routes/x+/jobs.$workCenterId.tsx+++ b/apps/mes/app/routes/x+/jobs.$workCenterId.tsx@@ -35,6 +35,7 @@ import {getWorkCentersByLocation,} from "~/services/jobs.service";import {+ clearLocationAndWorkCenter,getLocationAndWorkCenter,setLocationAndWorkCenter,} from "~/services/location.server";@@ -56,10 +57,10 @@ export async function loader({ request, params }: LoaderFunctionArgs) {});const workCenter = await getWorkCenter(client, workCenterId);- if (workCenter.error) {- throw redirect(path.to.recent, {+ if (workCenter.error || workCenter.data?.companyId !== companyId) {+ throw redirect(path.to.authenticatedRoot, {headers: {- "Set-Cookie": setLocationAndWorkCenter("", ""),+ "Set-Cookie": clearLocationAndWorkCenter(),},});}diff --git a/apps/mes/app/services/location.server.ts b/apps/mes/app/services/location.server.tsindex d2885fe23a..1fb0e51f5a 100644--- a/apps/mes/app/services/location.server.ts+++ b/apps/mes/app/services/location.server.ts@@ -35,6 +35,17 @@ export function setWorkCenter(workCenter: string) {});}+export function clearLocationAndWorkCenter() {+ return [+ cookie.serialize(locationCookieName, "", {+ path: "/",+ }),+ cookie.serialize(workCenterCookieName, "", {+ path: "/",+ }),+ ].join(",");+}+export function setLocationAndWorkCenter(currentLocation: string,workCenter: string