Files
kin/app/src/lib/config.ts
Marcus Rehbock ac0b82e6a0
Some checks failed
Build & Release APK / build (push) Failing after 13s
Kin: personal relationships app — server (cadence/due/migrations) + Expo Android app
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
2026-08-09 00:50:06 -07:00

33 lines
1.0 KiB
TypeScript

import AsyncStorage from "@react-native-async-storage/async-storage";
export const DEFAULT_URL = "https://crm.rehbock.xyz/api";
const KEYS = { url: "kin_api_url", token: "kin_api_token", hour: "kin_notif_hour" };
let cached: { url: string; token: string; notifHour: number } | null = null;
export async function getConfig() {
if (cached) return cached;
const [url, token, hour] = await Promise.all([
AsyncStorage.getItem(KEYS.url),
AsyncStorage.getItem(KEYS.token),
AsyncStorage.getItem(KEYS.hour),
]);
cached = {
url: url || DEFAULT_URL,
token: token || "",
notifHour: hour ? Number(hour) : 9,
};
return cached;
}
export async function setConfig(url: string, token: string, notifHour: number) {
const cleanUrl = (url.trim() || DEFAULT_URL).replace(/\/+$/, "");
cached = { url: cleanUrl, token: token.trim(), notifHour };
await Promise.all([
AsyncStorage.setItem(KEYS.url, cleanUrl),
AsyncStorage.setItem(KEYS.token, cached.token),
AsyncStorage.setItem(KEYS.hour, String(notifHour)),
]);
}