mirror of
https://github.com/bknd-io/bknd/
synced 2026-08-03 16:46:00 +00:00
Enhance authentication and authorization components
- Refactored `AppAuth` to introduce `getGuardContextSchema` for improved user context handling. - Updated `Authenticator` to utilize `pickKeys` for user data extraction in JWT generation. - Enhanced `Guard` class to improve permission checks and error handling. - Modified `SystemController` to return context schema alongside permissions in API responses. - Added new `permissions` method in `SystemApi` for fetching permissions. - Improved UI components with additional props and tooltip support for better user experience.
This commit is contained in:
@@ -5,13 +5,15 @@ import { twMerge } from "tailwind-merge";
|
||||
import { Link } from "ui/components/wouter/Link";
|
||||
|
||||
const sizes = {
|
||||
smaller: "px-1.5 py-1 rounded-md gap-1 !text-xs",
|
||||
small: "px-2 py-1.5 rounded-md gap-1 text-sm",
|
||||
default: "px-3 py-2.5 rounded-md gap-1.5",
|
||||
large: "px-4 py-3 rounded-md gap-2.5 text-lg",
|
||||
};
|
||||
|
||||
const iconSizes = {
|
||||
small: 12,
|
||||
smaller: 12,
|
||||
small: 14,
|
||||
default: 16,
|
||||
large: 20,
|
||||
};
|
||||
|
||||
@@ -0,0 +1,73 @@
|
||||
import { useEffect, useState } from "react";
|
||||
import { useTheme } from "ui/client/use-theme";
|
||||
import { cn } from "ui/lib/utils";
|
||||
|
||||
export type CodePreviewProps = {
|
||||
code: string;
|
||||
className?: string;
|
||||
lang?: string;
|
||||
theme?: string;
|
||||
enabled?: boolean;
|
||||
};
|
||||
|
||||
export const CodePreview = ({
|
||||
code,
|
||||
className,
|
||||
lang = "typescript",
|
||||
theme: _theme,
|
||||
enabled = true,
|
||||
}: CodePreviewProps) => {
|
||||
const [highlightedHtml, setHighlightedHtml] = useState<string | null>(null);
|
||||
const $theme = useTheme();
|
||||
const theme = (_theme ?? $theme.theme === "dark") ? "github-dark" : "github-light";
|
||||
|
||||
useEffect(() => {
|
||||
if (!enabled) return;
|
||||
|
||||
let cancelled = false;
|
||||
setHighlightedHtml(null);
|
||||
|
||||
async function highlightCode() {
|
||||
try {
|
||||
// Dynamically import Shiki from CDN
|
||||
// @ts-expect-error - Dynamic CDN import
|
||||
const { codeToHtml } = await import("https://esm.sh/shiki@3.13.0");
|
||||
|
||||
if (cancelled) return;
|
||||
|
||||
const html = await codeToHtml(code, {
|
||||
lang,
|
||||
theme,
|
||||
structure: "inline",
|
||||
});
|
||||
|
||||
if (cancelled) return;
|
||||
|
||||
setHighlightedHtml(html);
|
||||
} catch (error) {
|
||||
console.error("Failed to load Shiki:", error);
|
||||
// Fallback to plain text if Shiki fails to load
|
||||
if (!cancelled) {
|
||||
setHighlightedHtml(code);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
highlightCode();
|
||||
|
||||
return () => {
|
||||
cancelled = true;
|
||||
};
|
||||
}, [code, enabled]);
|
||||
|
||||
if (!highlightedHtml) {
|
||||
return <pre className={cn("select-text cursor-text", className)}>{code}</pre>;
|
||||
}
|
||||
|
||||
return (
|
||||
<pre
|
||||
className={cn("select-text cursor-text", className)}
|
||||
dangerouslySetInnerHTML={{ __html: highlightedHtml }}
|
||||
/>
|
||||
);
|
||||
};
|
||||
@@ -1,4 +1,4 @@
|
||||
import { IconBug } from "@tabler/icons-react";
|
||||
import { IconBug, IconInfoCircle } from "@tabler/icons-react";
|
||||
import type { JsonSchema } from "json-schema-library";
|
||||
import { Children, type ReactElement, type ReactNode, cloneElement, isValidElement } from "react";
|
||||
import { IconButton } from "ui/components/buttons/IconButton";
|
||||
@@ -12,6 +12,7 @@ import {
|
||||
import { Popover } from "ui/components/overlay/Popover";
|
||||
import { getLabel } from "./utils";
|
||||
import { twMerge } from "tailwind-merge";
|
||||
import { Tooltip } from "@mantine/core";
|
||||
|
||||
export type FieldwrapperProps = {
|
||||
name: string;
|
||||
@@ -24,7 +25,7 @@ export type FieldwrapperProps = {
|
||||
children: ReactElement | ReactNode;
|
||||
errorPlacement?: "top" | "bottom";
|
||||
description?: string;
|
||||
descriptionPlacement?: "top" | "bottom";
|
||||
descriptionPlacement?: "top" | "bottom" | "label";
|
||||
fieldId?: string;
|
||||
className?: string;
|
||||
};
|
||||
@@ -53,11 +54,17 @@ export function FieldWrapper({
|
||||
<Formy.ErrorMessage>{errors.map((e) => e.message).join(", ")}</Formy.ErrorMessage>
|
||||
);
|
||||
|
||||
const Description = description && (
|
||||
<Formy.Help className={descriptionPlacement === "top" ? "-mt-1 mb-1" : "mb-2"}>
|
||||
{description}
|
||||
</Formy.Help>
|
||||
);
|
||||
const Description = description ? (
|
||||
["top", "bottom"].includes(descriptionPlacement) ? (
|
||||
<Formy.Help className={descriptionPlacement === "top" ? "-mt-1 mb-1" : "mb-2"}>
|
||||
{description}
|
||||
</Formy.Help>
|
||||
) : (
|
||||
<Tooltip label={description}>
|
||||
<IconInfoCircle className="size-4 opacity-50" />
|
||||
</Tooltip>
|
||||
)
|
||||
) : null;
|
||||
|
||||
return (
|
||||
<Formy.Group
|
||||
@@ -72,9 +79,10 @@ export function FieldWrapper({
|
||||
<Formy.Label
|
||||
as={wrapper === "fieldset" ? "legend" : "label"}
|
||||
htmlFor={fieldId}
|
||||
className="self-start"
|
||||
className="self-start flex flex-row gap-1 items-center"
|
||||
>
|
||||
{label} {required && <span className="font-medium opacity-30">*</span>}
|
||||
{descriptionPlacement === "label" && Description}
|
||||
</Formy.Label>
|
||||
)}
|
||||
{descriptionPlacement === "top" && Description}
|
||||
|
||||
Reference in New Issue
Block a user