Skip to content

armgit / Cap

Public Imported from GitHub
0

Open source Loom alternative. Beautiful, shareable screen recordings.

666 B
Raw Blame
"use client";

import { createContext, type PropsWithChildren, useContext } from "react";

type PublicEnvContext = {
	webUrl: string;
	googleAuthAvailable: boolean;
	workosAuthAvailable: boolean;
	oidcAuthAvailable: boolean;
	oidcName: string;
};

const Context = createContext<PublicEnvContext | null>(null);

export function PublicEnvContext(
	props: { value: PublicEnvContext } & PropsWithChildren,
) {
	return (
		<Context.Provider value={props.value}>{props.children}</Context.Provider>
	);
}

export function usePublicEnv() {
	const ctx = useContext(Context);
	if (!ctx)
		throw new Error("usePublicEnv must be used within a PublicEnvContext");
	return ctx;
}