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.

feat: only show login with google or outlook if we have client ids

Brad Barbin4fe1416eb806
diff --git a/apps/academy/app/routes/_auth+/login.tsx b/apps/academy/app/routes/_auth+/login.tsx
index 3c971b33cc..2e1128461e 100644
--- a/apps/academy/app/routes/_auth+/login.tsx
+++ b/apps/academy/app/routes/_auth+/login.tsx
@@ -3,7 +3,9 @@ import {
carbonClient,
error,
magicLinkValidator,
- RATE_LIMIT
+ RATE_LIMIT,
+ SUPABASE_AUTH_EXTERNAL_AZURE_CLIENT_ID,
+ SUPABASE_AUTH_EXTERNAL_GOOGLE_CLIENT_ID
} from "@carbon/auth";
import { sendMagicLink, verifyAuthSession } from "@carbon/auth/auth.server";
import { flash, getAuthSession } from "@carbon/auth/session.server";
@@ -26,7 +28,13 @@ import type {
LoaderFunctionArgs,
MetaFunction
} from "react-router";
-import { data, redirect, useFetcher, useSearchParams } from "react-router";
+import {
+ data,
+ redirect,
+ useFetcher,
+ useLoaderData,
+ useSearchParams
+} from "react-router";
import { path } from "~/utils/path";
@@ -40,7 +48,10 @@ export async function loader({ request }: LoaderFunctionArgs) {
throw redirect(path.to.root);
}
- return null;
+ return {
+ hasOutlookAuth: !!SUPABASE_AUTH_EXTERNAL_AZURE_CLIENT_ID,
+ hasGoogleAuth: !!SUPABASE_AUTH_EXTERNAL_GOOGLE_CLIENT_ID
+ };
}
const ratelimit = new Ratelimit({
@@ -92,6 +103,7 @@ export async function action({ request }: ActionFunctionArgs) {
}
export default function LoginRoute() {
+ const { hasOutlookAuth, hasGoogleAuth } = useLoaderData<typeof loader>();
const [searchParams] = useSearchParams();
const redirectTo = searchParams.get("redirectTo") ?? undefined;
@@ -174,28 +186,32 @@ export default function LoginRoute() {
Sign in with Email
</Submit>
- <Button
- type="button"
- size="lg"
- className="w-full"
- onClick={onSignInWithGoogle}
- isDisabled={fetcher.state !== "idle"}
- variant="secondary"
- leftIcon={<GoogleIcon />}
- >
- Sign in with Google
- </Button>
- <Button
- type="button"
- size="lg"
- className="w-full"
- onClick={onSignInWithAzure}
- isDisabled={fetcher.state !== "idle"}
- variant="secondary"
- leftIcon={<OutlookIcon className="size-6" />}
- >
- Sign in with Outlook
- </Button>
+ {hasGoogleAuth && (
+ <Button
+ type="button"
+ size="lg"
+ className="w-full"
+ onClick={onSignInWithGoogle}
+ isDisabled={fetcher.state !== "idle"}
+ variant="secondary"
+ leftIcon={<GoogleIcon />}
+ >
+ Sign in with Google
+ </Button>
+ )}
+ {hasOutlookAuth && (
+ <Button
+ type="button"
+ size="lg"
+ className="w-full"
+ onClick={onSignInWithAzure}
+ isDisabled={fetcher.state !== "idle"}
+ variant="secondary"
+ leftIcon={<OutlookIcon className="size-6" />}
+ >
+ Sign in with Outlook
+ </Button>
+ )}
</VStack>
</ValidatedForm>
)}
diff --git a/apps/erp/app/routes/_public+/login.tsx b/apps/erp/app/routes/_public+/login.tsx
index 7cfaed2080..5ee87ba358 100644
--- a/apps/erp/app/routes/_public+/login.tsx
+++ b/apps/erp/app/routes/_public+/login.tsx
@@ -7,7 +7,9 @@ import {
carbonClient,
error,
magicLinkValidator,
- RATE_LIMIT
+ RATE_LIMIT,
+ SUPABASE_AUTH_EXTERNAL_AZURE_CLIENT_ID,
+ SUPABASE_AUTH_EXTERNAL_GOOGLE_CLIENT_ID
} from "@carbon/auth";
import { sendMagicLink, verifyAuthSession } from "@carbon/auth/auth.server";
import { flash, getAuthSession } from "@carbon/auth/session.server";
@@ -35,9 +37,15 @@ import type {
LoaderFunctionArgs,
MetaFunction
} from "react-router";
-import { data, redirect, useFetcher, useSearchParams } from "react-router";
+import {
+ data,
+ redirect,
+ useFetcher,
+ useLoaderData,
+ useSearchParams
+} from "react-router";
-import type { FormActionData, Result } from "~/types";
+import type { Result } from "~/types";
import { path } from "~/utils/path";
export const meta: MetaFunction = () => {
@@ -50,7 +58,10 @@ export async function loader({ request }: LoaderFunctionArgs) {
throw redirect(path.to.authenticatedRoot);
}
- return null;
+ return {
+ hasOutlookAuth: !!SUPABASE_AUTH_EXTERNAL_AZURE_CLIENT_ID,
+ hasGoogleAuth: !!SUPABASE_AUTH_EXTERNAL_GOOGLE_CLIENT_ID
+ };
}
const ratelimit = new Ratelimit({
@@ -59,7 +70,7 @@ const ratelimit = new Ratelimit({
analytics: true
});
-export async function action({ request }: ActionFunctionArgs): FormActionData {
+export async function action({ request }: ActionFunctionArgs) {
assertIsPost(request);
const ip = request.headers.get("x-forwarded-for") ?? "127.0.0.1";
const { success } = await ratelimit.limit(ip);
@@ -145,6 +156,7 @@ export async function action({ request }: ActionFunctionArgs): FormActionData {
}
export default function LoginRoute() {
+ const { hasOutlookAuth, hasGoogleAuth } = useLoaderData<typeof loader>();
const [searchParams] = useSearchParams();
const redirectTo = searchParams.get("redirectTo") ?? undefined;
const [mode, setMode] = useState<"login" | "signup" | "verify">("login");
@@ -292,28 +304,32 @@ export default function LoginRoute() {
</div>
)}
- <Button
- type="button"
- size="lg"
- className="w-full"
- onClick={onSignInWithGoogle}
- isDisabled={fetcher.state !== "idle"}
- variant="secondary"
- leftIcon={<GoogleIcon />}
- >
- Sign in with Google
- </Button>
- <Button
- type="button"
- size="lg"
- className="w-full"
- onClick={onSignInWithAzure}
- isDisabled={fetcher.state !== "idle"}
- variant="secondary"
- leftIcon={<OutlookIcon className="size-6" />}
- >
- Sign in with Outlook
- </Button>
+ {hasGoogleAuth && (
+ <Button
+ type="button"
+ size="lg"
+ className="w-full"
+ onClick={onSignInWithGoogle}
+ isDisabled={fetcher.state !== "idle"}
+ variant="secondary"
+ leftIcon={<GoogleIcon />}
+ >
+ Sign in with Google
+ </Button>
+ )}
+ {hasOutlookAuth && (
+ <Button
+ type="button"
+ size="lg"
+ className="w-full"
+ onClick={onSignInWithAzure}
+ isDisabled={fetcher.state !== "idle"}
+ variant="secondary"
+ leftIcon={<OutlookIcon className="size-6" />}
+ >
+ Sign in with Outlook
+ </Button>
+ )}
</VStack>
</ValidatedForm>
)}
diff --git a/apps/mes/app/routes/_public+/login.tsx b/apps/mes/app/routes/_public+/login.tsx
index c5eb44463d..9cbbeba3cd 100644
--- a/apps/mes/app/routes/_public+/login.tsx
+++ b/apps/mes/app/routes/_public+/login.tsx
@@ -5,7 +5,9 @@ import {
carbonClient,
error,
magicLinkValidator,
- RATE_LIMIT
+ RATE_LIMIT,
+ SUPABASE_AUTH_EXTERNAL_AZURE_CLIENT_ID,
+ SUPABASE_AUTH_EXTERNAL_GOOGLE_CLIENT_ID
} from "@carbon/auth";
import { sendMagicLink, verifyAuthSession } from "@carbon/auth/auth.server";
import { flash, getAuthSession } from "@carbon/auth/session.server";
@@ -30,7 +32,13 @@ import type {
LoaderFunctionArgs,
MetaFunction
} from "react-router";
-import { data, redirect, useFetcher, useSearchParams } from "react-router";
+import {
+ data,
+ redirect,
+ useFetcher,
+ useLoaderData,
+ useSearchParams
+} from "react-router";
import { path } from "~/utils/path";
@@ -44,7 +52,10 @@ export async function loader({ request }: LoaderFunctionArgs) {
throw redirect(path.to.authenticatedRoot);
}
- return null;
+ return {
+ hasOutlookAuth: !!SUPABASE_AUTH_EXTERNAL_AZURE_CLIENT_ID,
+ hasGoogleAuth: !!SUPABASE_AUTH_EXTERNAL_GOOGLE_CLIENT_ID
+ };
}
const ratelimit = new Ratelimit({
@@ -96,6 +107,7 @@ export async function action({ request }: ActionFunctionArgs) {
}
export default function LoginRoute() {
+ const { hasOutlookAuth, hasGoogleAuth } = useLoaderData<typeof loader>();
const [searchParams] = useSearchParams();
const redirectTo = searchParams.get("redirectTo") ?? undefined;
@@ -182,28 +194,32 @@ export default function LoginRoute() {
Sign in with Email
</Submit>
- <Button
- type="button"
- size="lg"
- className="w-full"
- onClick={onSignInWithGoogle}
- isDisabled={fetcher.state !== "idle"}
- variant="secondary"
- leftIcon={<GoogleIcon />}
- >
- Sign in with Google
- </Button>
- <Button
- type="button"
- size="lg"
- className="w-full"
- onClick={onSignInWithAzure}
- isDisabled={fetcher.state !== "idle"}
- variant="secondary"
- leftIcon={<OutlookIcon className="size-6" />}
- >
- Sign in with Outlook
- </Button>
+ {hasGoogleAuth && (
+ <Button
+ type="button"
+ size="lg"
+ className="w-full"
+ onClick={onSignInWithGoogle}
+ isDisabled={fetcher.state !== "idle"}
+ variant="secondary"
+ leftIcon={<GoogleIcon />}
+ >
+ Sign in with Google
+ </Button>
+ )}
+ {hasOutlookAuth && (
+ <Button
+ type="button"
+ size="lg"
+ className="w-full"
+ onClick={onSignInWithAzure}
+ isDisabled={fetcher.state !== "idle"}
+ variant="secondary"
+ leftIcon={<OutlookIcon className="size-6" />}
+ >
+ Sign in with Outlook
+ </Button>
+ )}
</VStack>
</ValidatedForm>
)}
diff --git a/apps/starter/app/routes/_public+/login.tsx b/apps/starter/app/routes/_public+/login.tsx
index 5143d41a30..38c146a91b 100644
--- a/apps/starter/app/routes/_public+/login.tsx
+++ b/apps/starter/app/routes/_public+/login.tsx
@@ -3,7 +3,9 @@ import {
carbonClient,
error,
magicLinkValidator,
- RATE_LIMIT
+ RATE_LIMIT,
+ SUPABASE_AUTH_EXTERNAL_AZURE_CLIENT_ID,
+ SUPABASE_AUTH_EXTERNAL_GOOGLE_CLIENT_ID
} from "@carbon/auth";
import { sendMagicLink, verifyAuthSession } from "@carbon/auth/auth.server";
import { flash, getAuthSession } from "@carbon/auth/session.server";
@@ -26,7 +28,13 @@ import type {
LoaderFunctionArgs,
MetaFunction
} from "react-router";
-import { data, redirect, useFetcher, useSearchParams } from "react-router";
+import {
+ data,
+ redirect,
+ useFetcher,
+ useLoaderData,
+ useSearchParams
+} from "react-router";
import { path } from "~/utils/path";
@@ -40,7 +48,10 @@ export async function loader({ request }: LoaderFunctionArgs) {
throw redirect(path.to.authenticatedRoot);
}
- return null;
+ return {
+ hasOutlookAuth: !!SUPABASE_AUTH_EXTERNAL_AZURE_CLIENT_ID,
+ hasGoogleAuth: !!SUPABASE_AUTH_EXTERNAL_GOOGLE_CLIENT_ID
+ };
}
const ratelimit = new Ratelimit({
@@ -92,6 +103,7 @@ export async function action({ request }: ActionFunctionArgs) {
}
export default function LoginRoute() {
+ const { hasOutlookAuth, hasGoogleAuth } = useLoaderData<typeof loader>();
const [searchParams] = useSearchParams();
const redirectTo = searchParams.get("redirectTo") ?? undefined;
@@ -174,28 +186,32 @@ export default function LoginRoute() {
Sign in with Email
</Submit>
- <Button
- type="button"
- size="lg"
- className="w-full"
- onClick={onSignInWithGoogle}
- isDisabled={fetcher.state !== "idle"}
- variant="secondary"
- leftIcon={<GoogleIcon />}
- >
- Sign in with Google
- </Button>
- <Button
- type="button"
- size="lg"
- className="w-full"
- onClick={onSignInWithAzure}
- isDisabled={fetcher.state !== "idle"}
- variant="secondary"
- leftIcon={<OutlookIcon className="size-6" />}
- >
- Sign in with Outlook
- </Button>
+ {hasGoogleAuth && (
+ <Button
+ type="button"
+ size="lg"
+ className="w-full"
+ onClick={onSignInWithGoogle}
+ isDisabled={fetcher.state !== "idle"}
+ variant="secondary"
+ leftIcon={<GoogleIcon />}
+ >
+ Sign in with Google
+ </Button>
+ )}
+ {hasOutlookAuth && (
+ <Button
+ type="button"
+ size="lg"
+ className="w-full"
+ onClick={onSignInWithAzure}
+ isDisabled={fetcher.state !== "idle"}
+ variant="secondary"
+ leftIcon={<OutlookIcon className="size-6" />}
+ >
+ Sign in with Outlook
+ </Button>
+ )}
</VStack>
</ValidatedForm>
)}
diff --git a/packages/auth/src/config/env.ts b/packages/auth/src/config/env.ts
index 3ccd973982..cda39b00a0 100644
--- a/packages/auth/src/config/env.ts
+++ b/packages/auth/src/config/env.ts
@@ -47,6 +47,8 @@ declare global {
SUPABASE_ANON_KEY: string;
SUPABASE_URL: string;
SUPABASE_DB_URL: string;
+ SUPABASE_AUTH_EXTERNAL_AZURE_CLIENT_ID: string;
+ SUPABASE_AUTH_EXTERNAL_GOOGLE_CLIENT_ID: string;
SUPABASE_SERVICE_ROLE_KEY: string;
UPSTASH_REDIS_REST_URL: string;
UPSTASH_REDIS_REST_TOKEN: string;
@@ -182,6 +184,21 @@ export const SUPABASE_DB_URL = getEnv("SUPABASE_DB_URL", {
isSecret: true,
isRequired: true
});
+export const SUPABASE_AUTH_EXTERNAL_AZURE_CLIENT_ID = getEnv(
+ "SUPABASE_AUTH_EXTERNAL_AZURE_CLIENT_ID",
+ {
+ isRequired: false,
+ isSecret: true
+ }
+);
+export const SUPABASE_AUTH_EXTERNAL_GOOGLE_CLIENT_ID = getEnv(
+ "SUPABASE_AUTH_EXTERNAL_GOOGLE_CLIENT_ID",
+ {
+ isRequired: false,
+ isSecret: true
+ }
+);
+
export const SESSION_SECRET = getEnv("SESSION_SECRET");
export const SESSION_KEY = "auth";
export const SESSION_ERROR_KEY = "error";