UNPKG

@kinde-oss/kinde-auth-react

Version:

Kinde React SDK for authentication

94 lines (93 loc) 2.33 kB
import { SessionBase as m, StorageKeys as y, splitString as l, storageSettings as r } from "./utils.mjs"; let i; async function o() { let n = 0; for (; !i && n < 20; ) await new Promise((e) => setTimeout(e, 100)), n++; } class g extends m { asyncStore = !0; constructor() { super(), this.loadExpoStore(); } async loadExpoStore() { try { i = await import( /* webpackIgnore: true */ "./js-utils-CMYq8l3H.js" ); } catch (e) { console.error("Error loading dependency expo storage:", e); } } /** * Clears all items from session store. * @returns {void} */ async destroySession() { const e = Object.values(y); await Promise.all(e.map((t) => this.removeSessionItem(t))), this.notifyListeners(); } /** * Sets the provided key-value store to ExpoSecureStore. * @param {string} itemKey * @param {unknown} itemValue * @returns {void} */ async setSessionItem(e, t) { if (await o(), await this.removeSessionItem(e), typeof t == "string") { const s = l( t, Math.min(r.maxLength, 2048) ); await Promise.all( s.map( (a, c) => i.setItemAsync( `${r.keyPrefix}${e}${c}`, a ) ) ), this.notifyListeners(); return; } else throw new Error("Item value must be a string"); } /** * Gets the item for the provided key from the ExpoSecureStore. * @param {string} itemKey * @returns {unknown | null} */ async getSessionItem(e) { await o(); const t = []; let s = 0, a = await i.getItemAsync( `${r.keyPrefix}${String(e)}${s}` ); for (; a; ) t.push(a), s++, a = await i.getItemAsync( `${r.keyPrefix}${String(e)}${s}` ); return t.join("") || null; } /** * Removes the item for the provided key from the ExpoSecureStore. * @param {string} itemKey * @returns {void} */ async removeSessionItem(e) { await o(); let t = 0, s = await i.getItemAsync( `${r.keyPrefix}${String(e)}${t}` ); for (; s; ) await i.deleteItemAsync( `${r.keyPrefix}${String(e)}${t}` ), t++, s = await i.getItemAsync( `${r.keyPrefix}${String(e)}${t}` ); this.notifyListeners(); } } export { g as ExpoSecureStore };