Skip to content

Commit 7245aaa

Browse files
committed
fix: ensure expo storage is loaded before using.
1 parent 3010015 commit 7245aaa

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

lib/sessionManager/stores/expoSecureStore.ts

+14
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,15 @@ import { splitString } from "../utils.js";
44

55
let expoSecureStore: typeof import("expo-secure-store") | undefined = undefined;
66

7+
async function waitForExpoSecureStore() {
8+
let tries = 0;
9+
while (!expoSecureStore && tries < 20) {
10+
console.log('waiting');
11+
await new Promise((resolve) => setTimeout(resolve, 100));
12+
tries++;
13+
}
14+
}
15+
716
/**
817
* Provides a expo local store based session manager implementation for the browser.
918
* @class ExpoSecureStore
@@ -42,6 +51,7 @@ export class ExpoSecureStore<V = StorageKeys> implements SessionManager<V> {
4251
itemKey: V | StorageKeys,
4352
itemValue: unknown,
4453
): Promise<void> {
54+
await waitForExpoSecureStore();
4555
// clear items first
4656
await this.removeSessionItem(itemKey);
4757

@@ -66,6 +76,8 @@ export class ExpoSecureStore<V = StorageKeys> implements SessionManager<V> {
6676
* @returns {unknown | null}
6777
*/
6878
async getSessionItem(itemKey: V | StorageKeys): Promise<unknown | null> {
79+
await waitForExpoSecureStore();
80+
6981
const chunks = [];
7082
let index = 0;
7183

@@ -91,6 +103,8 @@ export class ExpoSecureStore<V = StorageKeys> implements SessionManager<V> {
91103
* @returns {void}
92104
*/
93105
async removeSessionItem(itemKey: V | StorageKeys): Promise<void> {
106+
await waitForExpoSecureStore();
107+
94108
let index = 0;
95109

96110
let chunk = await expoSecureStore!.getItemAsync(

0 commit comments

Comments
 (0)