Self-hosted, federated location sharing app and server that prioritizes user privacy and security
end-to-end-encryption location-sharing privacy self-hosted federated
at auth 1.1 kB view raw
1import { Store as TauriStore } from "@tauri-apps/plugin-store"; 2 3type Settings = { 4 server_url: string; 5 user_id: string; 6 friends: { name: string; id: string }[]; 7 is_admin: boolean; 8 priv_key: string; 9}; 10 11export const Store = { 12 async get<T extends keyof Settings>(key: T): Promise<Settings[T]> { 13 const store = await TauriStore.load("settings.json"); 14 const value = await store.get<Settings[T]>(key); 15 if (value === undefined) { 16 alert(`Key ${key} not found in store`); 17 throw new Error(`Key ${key} not found in store`); 18 } 19 return value; 20 }, 21 22 async set<T extends keyof Settings>(key: T, value: Settings[T]): Promise<void> { 23 const store = await TauriStore.load("settings.json"); 24 await store.set(key, value); 25 await store.save(); 26 }, 27 28 async isLoggedIn(): Promise<boolean> { 29 const store = await TauriStore.load("settings.json"); 30 const user_id = await store.get<string>("user_id"); 31 return user_id !== undefined; 32 }, 33 34 // FOR TESTING ONLY 35 async reset(): Promise<void> { 36 const store = await TauriStore.load("settings.json"); 37 await store.reset(); 38 await store.save(); 39 }, 40};