web-production-saas-starter/next_b2b_starter/lib/contexts/stytch-config-context.tsx
2025-12-16 18:54:41 +04:00

28 lines
690 B
TypeScript

"use client";
import { createContext, useContext } from "react";
import type { StytchClientConfig } from "@/lib/auth/config-types";
const StytchConfigContext = createContext<StytchClientConfig | null>(null);
export function StytchConfigProvider({
children,
config,
}: {
children: React.ReactNode;
config: StytchClientConfig;
}) {
return (
<StytchConfigContext.Provider value={config}>
{children}
</StytchConfigContext.Provider>
);
}
export function useStytchConfig(): StytchClientConfig {
const config = useContext(StytchConfigContext);
if (!config) {
throw new Error("useStytchConfig must be used within StytchConfigProvider");
}
return config;
}