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(auth): show company picker on passkey sign-in for multi-company users
sidgaikwadb737594a108f
diff --git a/apps/erp/app/routes/api+/passkey.authenticate.verify.ts b/apps/erp/app/routes/api+/passkey.authenticate.verify.tsindex ae6464d347..10062a416d 100644--- a/apps/erp/app/routes/api+/passkey.authenticate.verify.ts+++ b/apps/erp/app/routes/api+/passkey.authenticate.verify.ts@@ -7,6 +7,7 @@ import { setAuthSession } from "@carbon/auth/session.server";import type { WebAuthnCredential } from "@simplewebauthn/browser";import type { ActionFunctionArgs } from "react-router";import { data, redirect } from "react-router";+import { getEmployeeCompanies } from "~/modules/settings";import { path } from "~/utils/path";export async function action({ request }: ActionFunctionArgs) {@@ -111,19 +112,24 @@ export async function action({ request }: ActionFunctionArgs) {}const sessionCookie = await setAuthSession(request, { authSession });- const companyIdCookie = setCompanyId(authSession.companyId);+ const headers: [string, string][] = [["Set-Cookie", sessionCookie]];++ // Only finalize the active company for single-company users. Multi-company+ // users must actively choose: we leave the companyId cookie unset and let+ // x+/_layout bounce them to the picker — its presence is the "has chosen+ // this session" marker. Mirrors the magic-link callback contract.+ const employeeCompanies =+ (await getEmployeeCompanies(serviceRole, credRow.userId)).data ?? [];+ if (employeeCompanies.length <= 1) {+ headers.push(["Set-Cookie", setCompanyId(authSession.companyId)]);+ }const safeRedirect =redirectTo && redirectTo.startsWith("/") && !redirectTo.startsWith("//")? redirectTo: path.to.authenticatedRoot;- return redirect(safeRedirect, {- headers: [- ["Set-Cookie", sessionCookie],- ["Set-Cookie", companyIdCookie]- ]- });+ return redirect(safeRedirect, { headers });} catch {return data(error(null, "Sign-in failed. Please try again."), {status: 401