Kin: personal relationships app — server (cadence/due/migrations) + Expo Android app
Some checks failed
Build & Release APK / build (push) Failing after 13s
Some checks failed
Build & Release APK / build (push) Failing after 13s
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
32
app/src/lib/config.ts
Normal file
32
app/src/lib/config.ts
Normal file
@@ -0,0 +1,32 @@
|
||||
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)),
|
||||
]);
|
||||
}
|
||||
Reference in New Issue
Block a user