import { Preferences } from "@capacitor/preferences"; import type { TokenStore } from "./token-store"; /** Key the session JWT is filed under in `@capacitor/preferences`. */ const TOKEN_KEY = "auth_token"; /** * The native {@link TokenStore}: the session JWT persisted through * `@capacitor/preferences` (Android `SharedPreferences` under the hood), * so it survives app restarts the way the browser's httpOnly cookie * survives a page reload. * * Only ever installed (via `setTokenStore`, see `client.ts`) when * `Capacitor.isNativePlatform()` — the plain web build keeps the no-op * store and its cookie, and this module is never imported there (the * bootstrap in `main.tsx` `import()`s it lazily behind that check), so * `@capacitor/preferences` stays out of the web bundle. */ export const capacitorTokenStore: TokenStore = { async get() { const { value } = await Preferences.get({ key: TOKEN_KEY }); return value; }, async set(token) { await Preferences.set({ key: TOKEN_KEY, value: token }); }, async clear() { await Preferences.remove({ key: TOKEN_KEY }); }, };