import { load, Store } from '@tauri-apps/plugin-store' import { User } from './types' let store: Store | null = null async function getStore() { if (!store) store = await load('store.json') return store } export async function getAuthData() { const s = await getStore() const token = await s.get('token') const user = await s.get('user') return { token: token || null, user: user || null, isAuthenticated: !!token } } export async function saveAuthData(token: string, user: User) { const s = await getStore() await s.set('token', token) await s.set('user', user) await s.save() } export async function clearAuthData() { const s = await getStore() await s.delete('token') await s.delete('user') await s.delete('last_room_uuid') await s.save() } export async function setLastRoom(uuid: string) { if (!uuid || uuid === 'none') return const s = await getStore() await s.set('last_room_uuid', uuid) await s.save() } export async function getLastRoom(): Promise { const s = await getStore() return (await s.get('last_room_uuid')) ?? null }