@clerk/nextjs
Version:
Clerk SDK for NextJS
60 lines • 2.32 kB
JavaScript
import "../../chunk-BUSYA2B4.js";
import React, { Suspense } from "react";
import { getDynamicAuthData } from "../../server/buildClerkProps";
import { mergeNextClerkPropsWithEnv } from "../../utils/mergeNextClerkPropsWithEnv";
import { ClientClerkProvider } from "../client/ClerkProvider";
import { DynamicClerkScripts } from "./DynamicClerkScripts";
import { getKeylessStatus, KeylessProvider } from "./keyless-provider";
import { buildRequestLike } from "./utils";
const getDynamicClerkState = React.cache(async function getDynamicClerkState2() {
const request = await buildRequestLike();
const data = getDynamicAuthData(request);
return data;
});
async function ClerkProvider(props) {
const { children, dynamic, ...rest } = props;
const statePromiseOrValue = dynamic ? getDynamicClerkState() : void 0;
const propsWithEnvs = mergeNextClerkPropsWithEnv({
...rest,
// Even though we always cast to InitialState here, this might still be a promise.
// While not reflected in the public types, we do support this for React >= 19 for internal use.
initialState: statePromiseOrValue
});
const { shouldRunAsKeyless, runningWithClaimedKeys } = await getKeylessStatus(propsWithEnvs);
const scriptsSlot = dynamic ? /* @__PURE__ */ React.createElement(Suspense, null, /* @__PURE__ */ React.createElement(
DynamicClerkScripts,
{
publishableKey: propsWithEnvs.publishableKey,
__internal_clerkJSUrl: propsWithEnvs.__internal_clerkJSUrl,
__internal_clerkJSVersion: propsWithEnvs.__internal_clerkJSVersion,
__internal_clerkUIUrl: propsWithEnvs.__internal_clerkUIUrl,
__internal_clerkUIVersion: propsWithEnvs.__internal_clerkUIVersion,
domain: propsWithEnvs.domain,
proxyUrl: propsWithEnvs.proxyUrl,
prefetchUI: propsWithEnvs.prefetchUI
}
)) : void 0;
if (shouldRunAsKeyless) {
return /* @__PURE__ */ React.createElement(
KeylessProvider,
{
rest: propsWithEnvs,
runningWithClaimedKeys,
__internal_scriptsSlot: scriptsSlot
},
children
);
}
return /* @__PURE__ */ React.createElement(
ClientClerkProvider,
{
...propsWithEnvs,
__internal_scriptsSlot: scriptsSlot
},
children
);
}
export {
ClerkProvider
};
//# sourceMappingURL=ClerkProvider.js.map