UNPKG

autumn-js

Version:
43 lines (42 loc) 1.06 kB
import { jsx } from "react/jsx-runtime"; import { encryptData } from "../utils/encryptUtils"; import { setupAuthPlugin } from "./server/auth/authPlugin"; import { NextAutumnProvider } from "./client/NextAutumnProvider"; const notNullish = (value) => { return value !== null && value !== void 0; }; const AutumnProvider = ({ customerId, customerData, authPlugin, children }) => { if (typeof window !== "undefined") { throw new Error( "AutumnProvider must be used in a server component. It cannot be used in client components." ); } if (notNullish(customerId) && notNullish(authPlugin)) { throw new Error( "AutumnProvider cannot have both customerId and authPlugin provided." ); } let encryptedCustomerId = customerId ? encryptData(customerId) : void 0; if (authPlugin) { setupAuthPlugin({ useUser: true, ...authPlugin }); } return /* @__PURE__ */ jsx( NextAutumnProvider, { encryptedCustomerId, customerData, children } ); }; export { AutumnProvider };