Files
karakeep-mirror/apps/mobile/lib/utils.ts
Mohamed Bassem ec621bf55a feat(mobile): add custom headers configuration in sign-in screen (#2103)
* 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>
2025-11-08 18:04:46 +00:00

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,
};
}