@kinde-oss/kinde-auth-react
Version:
Kinde React SDK for authentication
89 lines (88 loc) • 2.15 kB
JavaScript
import { D as c, i as y, N as m, c as a } from "./index-7XdJNziI.js";
let r;
async function o() {
let n = 0;
for (; !r && n < 20; )
await new Promise((e) => setTimeout(e, 100)), n++;
}
class w extends c {
constructor() {
super(), this.loadExpoStore();
}
async loadExpoStore() {
try {
r = 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() {
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 (s, i) => {
await r.setItemAsync(
`${a.keyPrefix}${e}${i}`,
s
);
}
);
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, i = await r.getItemAsync(
`${a.keyPrefix}${String(e)}${s}`
);
for (; i; )
t.push(i), s++, i = await r.getItemAsync(
`${a.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 r.getItemAsync(
`${a.keyPrefix}${String(e)}${t}`
);
for (; s; )
await r.deleteItemAsync(
`${a.keyPrefix}${String(e)}${t}`
), t++, s = await r.getItemAsync(
`${a.keyPrefix}${String(e)}${t}`
);
}
}
export {
w as ExpoSecureStore
};