Skip to content

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.

fix(erp): a first sign-in with no company reaches onboarding (#1859)

Sid90817f49f294
diff --git a/apps/erp/app/modules/shared/app-shell.server.test.ts b/apps/erp/app/modules/shared/app-shell.server.test.ts
index f2c5c8642d..b8a6968cb8 100644
--- a/apps/erp/app/modules/shared/app-shell.server.test.ts
+++ b/apps/erp/app/modules/shared/app-shell.server.test.ts
@@ -53,6 +53,21 @@ describe("getAppShell", () => {
expect(shell.data?.groups).toEqual(["g1"]);
});
+ it("asks with a null company for a user who has none yet", async () => {
+ const { client, rpc } = clientReturning({
+ data: { companies: [], groups: [], user: { id: "u1" } },
+ error: null
+ });
+ const shell = await getAppShell(client, undefined, "u1");
+ // The key must be present: dropped, the API finds no such function.
+ expect(rpc).toHaveBeenCalledWith("get_app_shell", {
+ company_id: null,
+ user_id: "u1"
+ });
+ expect(shell.error).toBeNull();
+ expect(shell.data?.user).toEqual({ id: "u1" });
+ });
+
it("returns the error and no data when the read fails", async () => {
const error = { message: "boom" };
const { client } = clientReturning({ data: null, error });
diff --git a/apps/erp/app/modules/shared/shared.server.ts b/apps/erp/app/modules/shared/shared.server.ts
index b4e474f641..cb65a8d9fd 100644
--- a/apps/erp/app/modules/shared/shared.server.ts
+++ b/apps/erp/app/modules/shared/shared.server.ts
@@ -698,11 +698,17 @@ type AppShellRows = {
*/
export async function getAppShell(
client: SupabaseClient<Database>,
- companyId: string,
+ // Absent for someone who has signed in and has no company yet.
+ companyId: string | null | undefined,
userId: string
) {
const result = await client.rpc("get_app_shell", {
- company_id: companyId,
+ // Sent as null, never left out. An undefined key is dropped from the
+ // request, the API then looks for a `get_app_shell(user_id)` that does
+ // not exist, and a first sign-in was logged straight back out instead
+ // of being sent to onboarding. With null the function runs and returns
+ // the user with no company rows.
+ company_id: (companyId ?? null) as string,
user_id: userId
});
if (result.error || !result.data) {