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(auth): the instance's sign-up toggle closes the app's own signup path

Sidwebworksdb3da1b7077a
diff --git a/apps/erp/app/routes/_public+/callback.tsx b/apps/erp/app/routes/_public+/callback.tsx
index 15fc7d822e..91c9c56538 100644
--- a/apps/erp/app/routes/_public+/callback.tsx
+++ b/apps/erp/app/routes/_public+/callback.tsx
@@ -11,7 +11,9 @@ import { getCarbonServiceRole } from "@carbon/auth/client.server";
import { getCompanyId, setCompanyId } from "@carbon/auth/company.server";
import { userHasVerifiedTotpFactor } from "@carbon/auth/mfa.server";
import {
+ isPlatformSignupDisabled,
isSelfSignupBlockedForEmail,
+ PLATFORM_SIGNUP_DISABLED_MESSAGE,
SELF_SIGNUP_BLOCKED_MESSAGE
} from "@carbon/auth/self-signup.server";
import {
@@ -356,9 +358,15 @@ export async function action({ request }: ActionFunctionArgs) {
// to mint a session and leave the account: with no company it can access
// nothing, and a later legitimate invite reuses the same row
// (createEmployeeAccount), so there is nothing to tear down.
+ // The platform toggle closes this same OAuth seam: GoTrue exempts
+ // nothing here (the auth user already exists by the time this action
+ // runs), so a no-company, no-invite arrival is a self-signup however
+ // it authenticated.
+ const platformClosed =
+ pickable.length === 0 && (await isPlatformSignupDisabled());
if (
- pickable.length === 0 &&
- isSelfSignupBlockedForEmail(authSession.email)
+ platformClosed ||
+ (pickable.length === 0 && isSelfSignupBlockedForEmail(authSession.email))
) {
// ilike for the case fold only — escape LIKE metacharacters so %/_ in an
// address can never act as wildcards and match someone else's invite.
@@ -377,7 +385,15 @@ export async function action({ request }: ActionFunctionArgs) {
if (!pendingInvite.data?.length) {
return redirect(
path.to.root,
- await flash(request, error(null, SELF_SIGNUP_BLOCKED_MESSAGE))
+ await flash(
+ request,
+ error(
+ null,
+ platformClosed
+ ? PLATFORM_SIGNUP_DISABLED_MESSAGE
+ : SELF_SIGNUP_BLOCKED_MESSAGE
+ )
+ )
);
}
}
diff --git a/apps/erp/app/routes/_public+/login.tsx b/apps/erp/app/routes/_public+/login.tsx
index f84855b6fe..83593372a4 100644
--- a/apps/erp/app/routes/_public+/login.tsx
+++ b/apps/erp/app/routes/_public+/login.tsx
@@ -19,7 +19,9 @@ import {
} from "@carbon/auth/auth.server";
import { getCarbonServiceRole } from "@carbon/auth/client.server";
import {
+ isPlatformSignupDisabled,
isSelfSignupBlockedForEmail,
+ PLATFORM_SIGNUP_DISABLED_MESSAGE,
SELF_SIGNUP_BLOCKED_MESSAGE
} from "@carbon/auth/self-signup.server";
import {
@@ -247,6 +249,18 @@ export async function action({ request }: ActionFunctionArgs) {
{ success: false, message: "User record not found" },
await flash(request, error(null, "Failed to sign in"))
);
+ } else if (await isPlatformSignupDisabled()) {
+ // Self-hosted with sign-ups switched off: same refusal as Enterprise,
+ // but named — the person can act on "ask for an invitation".
+ logAuthEvent("login_failed", {
+ actor: email,
+ ip,
+ reason: "sign-ups disabled on this instance"
+ });
+ return data(
+ { success: false, message: PLATFORM_SIGNUP_DISABLED_MESSAGE },
+ await flash(request, error(null, PLATFORM_SIGNUP_DISABLED_MESSAGE))
+ );
} else if (isSelfSignupBlockedForEmail(email)) {
// Cloud self-signup rejects consumer email domains (self-signup-blocked-domains.txt).
logAuthEvent("login_failed", {
diff --git a/apps/erp/app/routes/_public+/verify.tsx b/apps/erp/app/routes/_public+/verify.tsx
index 60cd34a372..a07e7c300c 100644
--- a/apps/erp/app/routes/_public+/verify.tsx
+++ b/apps/erp/app/routes/_public+/verify.tsx
@@ -5,7 +5,9 @@ import {
signInWithEmail
} from "@carbon/auth/auth.server";
import {
+ isPlatformSignupDisabled,
isSelfSignupBlockedForEmail,
+ PLATFORM_SIGNUP_DISABLED_MESSAGE,
SELF_SIGNUP_BLOCKED_MESSAGE
} from "@carbon/auth/self-signup.server";
import {
@@ -100,6 +102,14 @@ export async function action({ request }: ActionFunctionArgs) {
await flash(request, error(null, SELF_SIGNUP_BLOCKED_MESSAGE))
);
}
+ // Same defense for the platform toggle: a code sent moments before the
+ // administrator switched sign-ups off must not still create an account.
+ if (await isPlatformSignupDisabled()) {
+ return data(
+ { success: false, message: PLATFORM_SIGNUP_DISABLED_MESSAGE },
+ await flash(request, error(null, PLATFORM_SIGNUP_DISABLED_MESSAGE))
+ );
+ }
// Verify the email code
const isCodeValid = await verifyEmailCode(email, code);
diff --git a/packages/auth/src/services/self-signup.server.ts b/packages/auth/src/services/self-signup.server.ts
index 5718b0773a..ffa691bfa0 100644
--- a/packages/auth/src/services/self-signup.server.ts
+++ b/packages/auth/src/services/self-signup.server.ts
@@ -1,4 +1,5 @@
import { CarbonEdition } from "@carbon/auth";
+import { SUPABASE_ANON_KEY, SUPABASE_URL } from "@carbon/env";
import { Edition } from "@carbon/utils";
// The list ships with this package and is bundled into the consuming app (ERP /
@@ -34,3 +35,45 @@ export function isSelfSignupBlockedForEmail(email: string): boolean {
const domain = email.split("@").pop()?.trim().toLowerCase();
return !!domain && blockedDomains.has(domain);
}
+
+/** Shown when the instance has sign-ups switched off. Invites still work. */
+export const PLATFORM_SIGNUP_DISABLED_MESSAGE =
+ "Sign-ups are disabled on this instance. Ask your administrator for an invitation.";
+
+let platformSignup: { disabled: boolean; at: number } | null = null;
+
+/**
+ * Whether this INSTANCE has sign-ups switched off — GoTrue's own
+ * `disable_signup`, read from its public settings endpoint.
+ *
+ * This is the self-hosted counterpart to the Cloud blocklist above. The
+ * app's signup path never touches GoTrue's /signup (accounts are created
+ * server-side with the service key, which GoTrue exempts by design — that
+ * is what keeps invitations working), so without this check the
+ * platform's toggle only guarded endpoints nobody calls.
+ *
+ * Cached for a minute; on a fetch failure the answer is the platform
+ * default (sign-ups allowed) rather than locking a Community instance out
+ * of its own front door because auth blipped.
+ */
+export async function isPlatformSignupDisabled(): Promise<boolean> {
+ if (CarbonEdition === Edition.Cloud) return false;
+ if (platformSignup && Date.now() - platformSignup.at < 60_000) {
+ return platformSignup.disabled;
+ }
+ if (!SUPABASE_URL || !SUPABASE_ANON_KEY) return false;
+ try {
+ const res = await fetch(`${SUPABASE_URL}/auth/v1/settings`, {
+ headers: { apikey: SUPABASE_ANON_KEY }
+ });
+ const settings: { disable_signup?: boolean } = await res.json();
+ platformSignup = { disabled: !!settings.disable_signup, at: Date.now() };
+ } catch (err) {
+ console.warn(
+ "could not read auth settings; treating sign-ups as allowed",
+ err
+ );
+ platformSignup = { disabled: false, at: Date.now() };
+ }
+ return platformSignup.disabled;
+}