frontend: disable Clerk only when publishable key is absent

This commit is contained in:
Ishaan (OpenClaw)
2026-02-06 22:56:07 +00:00
parent 527879b55e
commit 39d2e530a7
2 changed files with 5 additions and 20 deletions

View File

@@ -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();