//=========================================== // THIS FILE IS AUTO-GENERATED FROM TEMPLATE. DO NOT EDIT IT DIRECTLY UNLESS YOU ALSO EDIT THE CORRESPONDING FILE IN packages/template //=========================================== import { useContext } from "react"; import { HexclaveContext } from "../providers/hexclave-context"; import type { GetUserOptions as AppGetUserOptions, CurrentInternalUser, CurrentUser, StackClientApp } from "./hexclave-app"; type GetUserOptions = AppGetUserOptions & { projectIdMustMatch?: string, }; /** * Returns the current user object. Equivalent to `useStackApp().useUser()`. * * @returns the current user */ export function useUser(options: GetUserOptions & { or: 'redirect' | 'throw', projectIdMustMatch: "internal" }): CurrentInternalUser; export function useUser(options: GetUserOptions & { or: 'redirect' | 'throw' }): CurrentUser; export function useUser(options: GetUserOptions & { projectIdMustMatch: "internal" }): CurrentInternalUser | null; export function useUser(options?: GetUserOptions): CurrentUser | CurrentInternalUser | null; export function useUser(options: GetUserOptions = {}): CurrentUser | CurrentInternalUser | null { const hexclaveApp = useHexclaveApp(options); if (options.projectIdMustMatch && hexclaveApp.projectId !== options.projectIdMustMatch) { throw new Error("Unexpected project ID in useHexclaveApp: " + hexclaveApp.projectId); } if (options.projectIdMustMatch === "internal") { return hexclaveApp.useUser(options) as CurrentInternalUser; } else { return hexclaveApp.useUser(options) as CurrentUser; } } /** * Returns the current Hexclave app associated with the HexclaveProvider. * * @returns the current Hexclave app */ export function useHexclaveApp(options: { projectIdMustMatch?: ProjectId } = {}): StackClientApp { if (typeof useContext !== "function") { throw new Error("useHexclaveApp() can only be used in a React Client Component. Make sure you're not calling it from a Server Component, or any other environment."); } const context = useContext(HexclaveContext); if (context === null) { throw new Error("useHexclaveApp must be used within a HexclaveProvider"); } const hexclaveApp = context.app; if (options.projectIdMustMatch && hexclaveApp.projectId !== options.projectIdMustMatch) { throw new Error("Unexpected project ID in useHexclaveApp: " + hexclaveApp.projectId); } return hexclaveApp as StackClientApp; } /** * Returns the current Stack app associated with the StackProvider. * * @deprecated Use `useHexclaveApp` from the `@hexclave/*` package instead — same symbol, new brand name. See https://docs.hexclave.com/migration. * * @returns the current Stack app */ export function useStackApp(options: { projectIdMustMatch?: ProjectId } = {}): StackClientApp { return useHexclaveApp(options); }