frontend: make Clerk optional during build when key missing/invalid

This commit is contained in:
Ishaan (OpenClaw)
2026-02-06 22:35:17 +00:00
parent eec790455f
commit 9f0dd01b65
2 changed files with 31 additions and 9 deletions

View File

@@ -3,9 +3,9 @@ import "./globals.css";
import type { Metadata } from "next";
import type { ReactNode } from "react";
import { ClerkProvider } from "@clerk/nextjs";
import { IBM_Plex_Sans, Sora } from "next/font/google";
import { AuthProvider } from "@/components/providers/AuthProvider";
import { QueryProvider } from "@/components/providers/QueryProvider";
export const metadata: Metadata = {
@@ -29,14 +29,14 @@ const headingFont = Sora({
export default function RootLayout({ children }: { children: ReactNode }) {
return (
<ClerkProvider>
<html lang="en">
<body
className={`${bodyFont.variable} ${headingFont.variable} min-h-screen bg-app text-strong antialiased`}
>
<html lang="en">
<body
className={`${bodyFont.variable} ${headingFont.variable} min-h-screen bg-app text-strong antialiased`}
>
<AuthProvider>
<QueryProvider>{children}</QueryProvider>
</body>
</html>
</ClerkProvider>
</AuthProvider>
</body>
</html>
);
}

View File

@@ -0,0 +1,22 @@
"use client";
import { ClerkProvider } from "@clerk/nextjs";
import type { ReactNode } from "react";
function isLikelyValidClerkPublishableKey(key: string | undefined): key is string {
if (!key) return false;
// Clerk publishable keys look like: pk_test_... or pk_live_...
// In CI we want builds to stay secretless; if the key isn't present/valid,
// we skip Clerk entirely so `next build` can prerender.
return /^pk_(test|live)_[A-Za-z0-9]+$/.test(key);
}
export function AuthProvider({ children }: { children: ReactNode }) {
const publishableKey = process.env.NEXT_PUBLIC_CLERK_PUBLISHABLE_KEY;
if (!isLikelyValidClerkPublishableKey(publishableKey)) {
return <>{children}</>;
}
return <ClerkProvider publishableKey={publishableKey}>{children}</ClerkProvider>;
}