From 9f11170f8bd028e5cef600dcdeee7bf11be173b1 Mon Sep 17 00:00:00 2001 From: Julia Friesel Date: Fri, 14 Sep 2018 20:24:16 +0200 Subject: [PATCH] Bring back persist argument to openDb This reverts commit fc1028dba411711c46e3976693552632af4b9dc6. --- components/password-prompt.js | 4 ++-- db/index.js | 8 +++++--- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/components/password-prompt.js b/components/password-prompt.js index d86ea6e..78d1b93 100644 --- a/components/password-prompt.js +++ b/components/password-prompt.js @@ -18,7 +18,7 @@ export default class PasswordPrompt extends Component { if (hasEncryption) { this.setState({showPasswordPrompt: true}) } else { - await openDb() + await openDb({persistConnection: true}) this.props.showApp() } }) @@ -34,7 +34,7 @@ export default class PasswordPrompt extends Component { msg = JSON.parse(msg) if (msg.type != 'sha512') return try { - await openDb(msg.message) + await openDb({hash: msg.message, persistConnection: true }) } catch (err) { Alert.alert( shared.incorrectPassword, diff --git a/db/index.js b/db/index.js index 9745327..4173c1d 100644 --- a/db/index.js +++ b/db/index.js @@ -161,12 +161,14 @@ export function requestHash(pw) { })) } -export async function openDb (hash) { +export async function openDb ({ hash, persistConnection }) { if (hash) { realmConfig.encryptionKey = hashToInt8Array(hash) } - db = await Realm.open(realmConfig) + const connection = await Realm.open(realmConfig) + + if (persistConnection) db = connection } export async function changeEncryptionAndRestartApp(hash) { @@ -195,7 +197,7 @@ export async function changeEncryptionAndRestartApp(hash) { export async function deleteDbAndOpenNew() { const exists = await fs.exists(Realm.defaultPath) if (exists) await fs.unlink(Realm.defaultPath) - await openDb() + await openDb({ persistConnection: true }) await saveEncryptionFlag(false) }