@kinde-oss/kinde-auth-react
Version:
Kinde React SDK for authentication
86 lines (85 loc) • 2.1 kB
JavaScript
import { A as c, a as y, b as m, c as a } from "./index-DjNR3H6H.js";
let s;
async function o() {
let n = 0;
for (; !s && n < 20; )
await new Promise((e) => setTimeout(e, 100)), n++;
}
class w extends c {
constructor() {
super(), this.loadExpoStore();
}
async loadExpoStore() {
try {
s = await import("./js-utils-CMYq8l3H.js");
} catch (e) {
console.error("Error loading dependency expo storage:", e);
}
}
/**
* Clears all items from session store.
* @returns {void}
*/
async destroySession() {
Object.values(y).forEach(async (e) => {
await this.removeSessionItem(e);
});
}
/**
* 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") {
m(t, Math.min(a.maxLength, 2048)).forEach(
async (r, i) => {
await s.setItemAsync(
`${a.keyPrefix}${e}${i}`,
r
);
}
);
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 r = 0, i = await s.getItemAsync(
`${a.keyPrefix}${String(e)}${r}`
);
for (; i; )
t.push(i), r++, i = await s.getItemAsync(
`${a.keyPrefix}${String(e)}${r}`
);
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, r = await s.getItemAsync(
`${a.keyPrefix}${String(e)}${t}`
);
for (; r; )
await s.deleteItemAsync(
`${a.keyPrefix}${String(e)}${t}`
), t++, r = await s.getItemAsync(
`${a.keyPrefix}${String(e)}${t}`
);
}
}
export {
w as ExpoSecureStore
};