update cache on vault key update (#1752)

* update cache on vault key update

* Update components/vault/use-vault-configurator.js

Co-authored-by: ekzyis <ek@stacker.news>

---------

Co-authored-by: ekzyis <ek@stacker.news>
This commit is contained in:
Keyan 2024-12-20 18:15:06 -06:00 committed by GitHub
parent 6ad7a3cf60
commit f5fb88342b
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 13 additions and 2 deletions

View File

@ -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 }
}