mirror of
https://github.com/karakeep-app/karakeep.git
synced 2026-02-28 18:25:55 +01:00
* feat(mobile): add custom headers configuration in sign-in screen Add ability for mobile app users to configure custom HTTP headers that are sent with every API request. This enables users to add authentication headers, proxy headers, or other custom headers required by their server setup. Changes: - Add customHeaders field to mobile app settings schema - Create CustomHeadersModal component for managing headers - Update sign-in screen with link to configure custom headers - Modify tRPC provider to merge custom headers with Authorization header The custom headers are stored securely in the app settings and persist across sessions. * fix keyboard * add custom headers to other callsites --------- Co-authored-by: Claude <noreply@anthropic.com>
60 lines
1.4 KiB
TypeScript
60 lines
1.4 KiB
TypeScript
import type { ClassValue } from "clsx";
|
|
import { clsx } from "clsx";
|
|
import { twMerge } from "tailwind-merge";
|
|
|
|
export function cn(...inputs: ClassValue[]) {
|
|
return twMerge(clsx(inputs));
|
|
}
|
|
|
|
/**
|
|
* Merge props conditionally.
|
|
*
|
|
* @example
|
|
* ```
|
|
* <View {...condProps(
|
|
* { condition: true, props: { className: "foo" } },
|
|
* { condition: true, props: { style: { margin: "10px" } } },
|
|
* )} />
|
|
* ```
|
|
* results in:
|
|
* ```
|
|
* <View className="foo" style={ margin: "10px" } />
|
|
* ```
|
|
* @example
|
|
* ```
|
|
* <View style={condProps(
|
|
* { condition: true, color: "red" },
|
|
* { condition: true, fontWeight: "bold" }
|
|
* )} />
|
|
* ```
|
|
* results in:
|
|
* ```
|
|
* <View style={ color: "red", fontWeight: "bold" } />
|
|
* ```
|
|
*/
|
|
export function condProps(
|
|
...condProps: {
|
|
condition: boolean;
|
|
props: Record<string, unknown>;
|
|
}[]
|
|
): Record<string, unknown> {
|
|
return condProps.reduce((acc, { condition, props }) => {
|
|
return condition ? { ...acc, ...props } : acc;
|
|
}, {});
|
|
}
|
|
|
|
/**
|
|
* Build HTTP headers for API requests, merging Authorization and custom headers.
|
|
* This ensures all direct HTTP calls (uploads, downloads, health checks) respect
|
|
* the user's custom header configuration.
|
|
*/
|
|
export function buildApiHeaders(
|
|
apiKey: string | undefined,
|
|
customHeaders: Record<string, string> = {},
|
|
): Record<string, string> {
|
|
return {
|
|
...(apiKey ? { Authorization: `Bearer ${apiKey}` } : {}),
|
|
...customHeaders,
|
|
};
|
|
}
|