From 39d2e530a71667ded18ae85a09388a49d3e28101 Mon Sep 17 00:00:00 2001 From: "Ishaan (OpenClaw)" Date: Fri, 6 Feb 2026 22:56:07 +0000 Subject: [PATCH] frontend: disable Clerk only when publishable key is absent --- frontend/src/auth/clerk.tsx | 14 ++++---------- frontend/src/proxy.ts | 11 +---------- 2 files changed, 5 insertions(+), 20 deletions(-) diff --git a/frontend/src/auth/clerk.tsx b/frontend/src/auth/clerk.tsx index d5ee1dca..5dfcd62d 100644 --- a/frontend/src/auth/clerk.tsx +++ b/frontend/src/auth/clerk.tsx @@ -16,16 +16,10 @@ import { } from "@clerk/nextjs"; export function isClerkEnabled(): boolean { - const key = process.env.NEXT_PUBLIC_CLERK_PUBLISHABLE_KEY; - if (!key) return false; - - // Clerk validates publishable key contents at runtime; use a conservative heuristic. - const m = /^pk_(test|live)_([A-Za-z0-9]+)$/.exec(key); - if (!m) return false; - const body = m[2]; - if (body.length < 16) return false; - if (/^0+$/.test(body)) return false; - return true; + // Invariant: Clerk is disabled ONLY when the publishable key is absent. + // If a key is present, we assume Clerk is intended to be enabled and we let + // Clerk fail fast if the key is invalid/misconfigured. + return Boolean(process.env.NEXT_PUBLIC_CLERK_PUBLISHABLE_KEY); } export function SignedIn(props: { children: ReactNode }) { diff --git a/frontend/src/proxy.ts b/frontend/src/proxy.ts index 41a0eb80..75b30866 100644 --- a/frontend/src/proxy.ts +++ b/frontend/src/proxy.ts @@ -1,16 +1,7 @@ import { NextResponse } from "next/server"; import { clerkMiddleware } from "@clerk/nextjs/server"; -const isClerkEnabled = () => { - const key = process.env.NEXT_PUBLIC_CLERK_PUBLISHABLE_KEY; - if (!key) return false; - const m = /^pk_(test|live)_([A-Za-z0-9]+)$/.exec(key); - if (!m) return false; - const body = m[2]; - if (body.length < 16) return false; - if (/^0+$/.test(body)) return false; - return true; -}; +const isClerkEnabled = () => Boolean(process.env.NEXT_PUBLIC_CLERK_PUBLISHABLE_KEY); export default isClerkEnabled() ? clerkMiddleware() : () => NextResponse.next();