Files
cal.diy/apps/web/app/(use-page-wrapper)/layout.tsx
T
Hariom Balhara f905ae7502 fix: Add CSP back to login page (#22688)
* Middleware only logic to add CSP header as Next.js App Router doesnt allow setting header in server component

* add tests

* Remove nonce from Page Router and fix ts issues

* Add checkly test
2025-07-26 01:38:20 +01:00

42 lines
1.1 KiB
TypeScript

import { headers } from "next/headers";
import Script from "next/script";
import PageWrapper from "@components/PageWrapperAppDir";
export default async function PageWrapperLayout({ children }: { children: React.ReactNode }) {
const h = await headers();
const nonce = h.get("x-csp-nonce") ?? undefined;
const headScript = process.env.NEXT_PUBLIC_HEAD_SCRIPTS;
const bodyScript = process.env.NEXT_PUBLIC_BODY_SCRIPTS;
const scripts = [
{
id: "injected-head-script",
script: headScript ?? "",
},
{
id: "injected-body-script",
script: bodyScript ?? "",
},
].filter((script): script is { id: string; script: string } => !!script.script);
return (
<>
<PageWrapper requiresLicense={false} nonce={nonce}>
{children}
{scripts.map((script) => (
<Script
key={script.id}
nonce={nonce}
id={script.id}
// eslint-disable-next-line react/no-danger
dangerouslySetInnerHTML={{
__html: script.script,
}}
/>
))}
</PageWrapper>
</>
);
}