frontend: make Clerk optional during build when key missing/invalid
This commit is contained in:
@@ -3,9 +3,9 @@ import "./globals.css";
|
|||||||
import type { Metadata } from "next";
|
import type { Metadata } from "next";
|
||||||
import type { ReactNode } from "react";
|
import type { ReactNode } from "react";
|
||||||
|
|
||||||
import { ClerkProvider } from "@clerk/nextjs";
|
|
||||||
import { IBM_Plex_Sans, Sora } from "next/font/google";
|
import { IBM_Plex_Sans, Sora } from "next/font/google";
|
||||||
|
|
||||||
|
import { AuthProvider } from "@/components/providers/AuthProvider";
|
||||||
import { QueryProvider } from "@/components/providers/QueryProvider";
|
import { QueryProvider } from "@/components/providers/QueryProvider";
|
||||||
|
|
||||||
export const metadata: Metadata = {
|
export const metadata: Metadata = {
|
||||||
@@ -29,14 +29,14 @@ const headingFont = Sora({
|
|||||||
|
|
||||||
export default function RootLayout({ children }: { children: ReactNode }) {
|
export default function RootLayout({ children }: { children: ReactNode }) {
|
||||||
return (
|
return (
|
||||||
<ClerkProvider>
|
<html lang="en">
|
||||||
<html lang="en">
|
<body
|
||||||
<body
|
className={`${bodyFont.variable} ${headingFont.variable} min-h-screen bg-app text-strong antialiased`}
|
||||||
className={`${bodyFont.variable} ${headingFont.variable} min-h-screen bg-app text-strong antialiased`}
|
>
|
||||||
>
|
<AuthProvider>
|
||||||
<QueryProvider>{children}</QueryProvider>
|
<QueryProvider>{children}</QueryProvider>
|
||||||
</body>
|
</AuthProvider>
|
||||||
</html>
|
</body>
|
||||||
</ClerkProvider>
|
</html>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
22
frontend/src/components/providers/AuthProvider.tsx
Normal file
22
frontend/src/components/providers/AuthProvider.tsx
Normal 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>;
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user