Skip to content

Commit e029830

Browse files
authored
Merge pull request #2785 from GetStream/fix/db-open-close-issues
fix: db open close issues
2 parents f667148 + d353d32 commit e029830

File tree

2 files changed

+6
-2
lines changed

2 files changed

+6
-2
lines changed

examples/SampleApp/src/hooks/useChatClient.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,7 @@ export const useChatClient = () => {
181181
};
182182

183183
const logout = async () => {
184-
SqliteClient.resetDB();
184+
await SqliteClient.resetDB();
185185
setChatClient(null);
186186
chatClient?.disconnectUser();
187187
await AsyncStore.removeItem('@stream-rn-sampleapp-login-config');

package/src/store/SqliteClient.ts

+5-1
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ export class SqliteClient {
6666
throw new Error('DB is not open or initialized.');
6767
}
6868
this.db.close();
69+
this.db = undefined;
6970
} catch (e) {
7071
this.logger?.('error', `Error closing database ${SqliteClient.dbName}`, {
7172
error: e,
@@ -200,7 +201,10 @@ export class SqliteClient {
200201

201202
static resetDB = async () => {
202203
this.logger?.('info', `resetDB`);
203-
SqliteClient.dropTables();
204+
if (this.db) {
205+
await SqliteClient.dropTables();
206+
SqliteClient.closeDB();
207+
}
204208
await SqliteClient.initializeDatabase();
205209
};
206210
}

0 commit comments

Comments
 (0)