From f5fb88342be6de75ed15517c1c836b2bc0fb88a0 Mon Sep 17 00:00:00 2001 From: Keyan <34140557+huumn@users.noreply.github.com> Date: Fri, 20 Dec 2024 18:15:06 -0600 Subject: [PATCH] update cache on vault key update (#1752) * update cache on vault key update * Update components/vault/use-vault-configurator.js Co-authored-by: ekzyis --------- Co-authored-by: ekzyis --- components/vault/use-vault-configurator.js | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/components/vault/use-vault-configurator.js b/components/vault/use-vault-configurator.js index 7f087a1c..a3269f5a 100644 --- a/components/vault/use-vault-configurator.js +++ b/components/vault/use-vault-configurator.js @@ -37,7 +37,7 @@ export function useVaultConfigurator ({ onVaultKeySet, beforeDisconnectVault } = beforeDisconnectVault?.() await remove('key') keyReactiveVar(null) - }, [remove, keyReactiveVar]) + }, [remove, keyReactiveVar, beforeDisconnectVault]) useEffect(() => { if (!me) return @@ -94,6 +94,17 @@ export function useVaultConfigurator ({ onVaultKeySet, beforeDisconnectVault } = await updateVaultKey({ variables: { entries, hash: vaultKey.hash }, + update: (cache, { data }) => { + cache.modify({ + id: `User:${me.id}`, + fields: { + privates: (existing) => ({ + ...existing, + vaultKeyHash: vaultKey.hash + }) + } + }) + }, onError: (error) => { const errorCode = error.graphQLErrors[0]?.extensions?.code if (errorCode === E_VAULT_KEY_EXISTS) { @@ -110,7 +121,7 @@ export function useVaultConfigurator ({ onVaultKeySet, beforeDisconnectVault } = console.error('error setting vault key', e) toaster.danger(e.message) } - }, [getVaultEntries, updateVaultKey, set, get, remove, onVaultKeySet, keyReactiveVar]) + }, [getVaultEntries, updateVaultKey, set, get, remove, onVaultKeySet, keyReactiveVar, me?.id]) return { key, setVaultKey, clearVault, disconnectVault } }