import clsx from "clsx"; import { isDebug } from "core"; import { TbAlertCircle, 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 { Icon } from "ui/components/display/Icon"; import { Message } from "ui/components/display/Message"; import { Field, type FieldProps, Form, FormDebug, 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 { 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, debug: isDebug() }, }; function AuthSettingsInternal() { const { config, schema: _schema, actions, $auth } = 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 } > Settings )}
Guard Enabled {!$auth.roles.has_admin && ( )}
} disabled={$auth.roles.none} description="When enabled, enforces permissions on all routes. Make sure to create roles first." descriptionPlacement="top" />
); } 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 ; }