refactor(auth): standardize session management and security
- Centralize secret retrieval using `getAdminSessionSecret` - Replace manual session parsing with `verifyRequestAdminSession` utility - Tighten API validation and improve security headers handling - Enforce environment variable security for production deployments
This commit is contained in:
1 parent
34519c07df
commit
177ed4a844
78 files changed
+6748
-3157
No files matched your search
+41
-29
@@ -10,6 +10,46 @@ export interface ButtonProps extends React.ButtonHTMLAttributes<HTMLButtonElemen
|
||||
loading?: boolean;
|
||||
}
|
||||
|
||||
const BUTTON_BASE_STYLES =
|
||||
'inline-flex items-center justify-center font-normal transition-colors select-none cursor-pointer disabled:opacity-50 disabled:cursor-not-allowed border border-transparent whitespace-nowrap outline-none';
|
||||
|
||||
const BUTTON_VARIANT_STYLES = {
|
||||
primary:
|
||||
'bg-[var(--text)] text-[var(--bg)] hover:opacity-90 border-[var(--text)]',
|
||||
secondary:
|
||||
'bg-[var(--bg-elevated)] text-[var(--text)] border-[var(--border-strong)] hover:bg-[var(--bg-hover)]',
|
||||
ghost:
|
||||
'bg-transparent text-[var(--text-muted)] hover:text-[var(--text)] hover:bg-[var(--bg-hover)] border-transparent',
|
||||
danger:
|
||||
'bg-transparent text-[var(--danger)] border-[var(--danger)] hover:bg-[var(--danger-soft)]',
|
||||
icon:
|
||||
'bg-transparent text-[var(--text-muted)] hover:text-[var(--text)] hover:bg-[var(--bg-hover)] border-transparent p-0',
|
||||
} as const;
|
||||
|
||||
const BUTTON_SIZE_STYLES = {
|
||||
default: 'min-h-8.5 px-3 text-[12px] gap-1.5',
|
||||
sm: 'h-7.5 px-2.5 text-[11.5px] gap-1.5',
|
||||
xs: 'h-7 px-2 text-[11px] gap-1',
|
||||
icon: 'w-7.5 h-7.5 p-0',
|
||||
} as const;
|
||||
|
||||
export function buttonClassNames({
|
||||
variant = 'secondary',
|
||||
size = 'default',
|
||||
className,
|
||||
}: {
|
||||
variant?: keyof typeof BUTTON_VARIANT_STYLES;
|
||||
size?: keyof typeof BUTTON_SIZE_STYLES;
|
||||
className?: string;
|
||||
} = {}): string {
|
||||
return cn(
|
||||
BUTTON_BASE_STYLES,
|
||||
BUTTON_VARIANT_STYLES[variant],
|
||||
size === 'icon' ? BUTTON_SIZE_STYLES.icon : BUTTON_SIZE_STYLES[size],
|
||||
className
|
||||
);
|
||||
}
|
||||
|
||||
export const Button = React.forwardRef<HTMLButtonElement, ButtonProps>(
|
||||
(
|
||||
{
|
||||
@@ -25,39 +65,11 @@ export const Button = React.forwardRef<HTMLButtonElement, ButtonProps>(
|
||||
},
|
||||
ref
|
||||
) => {
|
||||
const baseStyles =
|
||||
'inline-flex items-center justify-center font-normal transition-colors select-none cursor-pointer disabled:opacity-50 disabled:cursor-not-allowed border border-transparent whitespace-nowrap outline-none';
|
||||
|
||||
const variantStyles = {
|
||||
primary:
|
||||
'bg-[var(--text)] text-[var(--bg)] hover:opacity-90 border-[var(--text)]',
|
||||
secondary:
|
||||
'bg-[var(--bg-elevated)] text-[var(--text)] border-[var(--border-strong)] hover:bg-[var(--bg-hover)]',
|
||||
ghost:
|
||||
'bg-transparent text-[var(--text-muted)] hover:text-[var(--text)] hover:bg-[var(--bg-hover)] border-transparent',
|
||||
danger:
|
||||
'bg-transparent text-[var(--danger)] border-[var(--danger)] hover:bg-[var(--danger-soft)]',
|
||||
icon:
|
||||
'bg-transparent text-[var(--text-muted)] hover:text-[var(--text)] hover:bg-[var(--bg-hover)] border-transparent p-0',
|
||||
};
|
||||
|
||||
const sizeStyles = {
|
||||
default: 'min-h-8.5 px-3 text-[12px] gap-1.5',
|
||||
sm: 'h-7.5 px-2.5 text-[11.5px] gap-1.5',
|
||||
xs: 'h-7 px-2 text-[11px] gap-1',
|
||||
icon: 'w-7.5 h-7.5 p-0',
|
||||
};
|
||||
|
||||
return (
|
||||
<button
|
||||
ref={ref}
|
||||
disabled={disabled || loading}
|
||||
className={cn(
|
||||
baseStyles,
|
||||
variantStyles[variant],
|
||||
size === 'icon' ? sizeStyles.icon : sizeStyles[size],
|
||||
className
|
||||
)}
|
||||
className={buttonClassNames({ variant, size, className })}
|
||||
{...props}
|
||||
>
|
||||
{loading ? (
|
||||
|
||||
Reference in new issue
Block a user