import clsx from "clsx"; import { TbChevronDown, TbChevronUp } from "react-icons/tb"; import { useBknd } from "ui/client/BkndProvider"; import { useBkndAuth } from "ui/client/schema/auth/use-bknd-auth"; import { Button } from "ui/components/buttons/Button"; import { Message } from "ui/components/display/Message"; import { Field, type FieldProps, Form, Subscribe } from "ui/components/form/json-schema-form"; import { useBrowserTitle } from "ui/hooks/use-browser-title"; import * as AppShell from "ui/layouts/AppShell/AppShell"; import { Breadcrumbs2 } from "ui/layouts/AppShell/Breadcrumbs2"; import { create } from "zustand"; import { combine } from "zustand/middleware"; const useAuthSettingsStore = create( combine( { advanced: [] as string[] }, (set) => ({ toggleAdvanced: (which: string) => set((state) => ({ advanced: state.advanced.includes(which) ? state.advanced.filter((w) => w !== which) : [...state.advanced, which] })) }) ) ); export function AuthSettings(props) { useBrowserTitle(["Auth", "Settings"]); const { hasSecrets } = useBknd({ withSecrets: true }); if (!hasSecrets) { return ; } return ; } const formConfig = { ignoreKeys: ["roles", "strategies"], options: { keepEmpty: true } }; function AuthSettingsInternal() { const { config, schema: _schema, actions } = useBkndAuth(); const schema = JSON.parse(JSON.stringify(_schema)); schema.properties.jwt.required = ["alg"]; async function onSubmit(data: any) { await actions.config.set(data); } return (
({ dirty: state.dirty, errors: state.errors.length > 0, submitting: state.submitting })} > {({ dirty, errors, submitting }) => ( Update } >
)}
{/* */}
); } const ToggleAdvanced = ({ which }: { which: string }) => { const { advanced, toggleAdvanced } = useAuthSettingsStore(); const show = advanced.includes(which); return ( ); }; //const Overlay = () => null; const Overlay = () => ( ({ enabled: state.data.enabled })}> {({ enabled }) => !enabled && (
) } ); function Section(props: { children: React.ReactNode; className?: string; title?: string; first?: boolean; }) { const { children, title, className } = props; return ( <>
{title &&

{title}

} {children}
); } function AuthField(props: FieldProps & { advanced?: string }) { const { advanced, ...rest } = props; const showAdvanced = useAuthSettingsStore((state) => state.advanced); if (advanced && !showAdvanced.includes(advanced)) return null; return ; }