updateSecret( )
Updates the specified fields of an existing secret by ID.
Description
The updateSecret()
function returns a Promise that resolves when the secret is successfully updated.
You can update one or more secret properties. Only the properties passed in the Secret object will be updated.
All other properties will remain the same.
You can retrieve the id
parameter from the listSecretInfo()
function.
The id
is not the same as the secret name
used by the getSecret()
function.
Notes:
Changing a secret's name or value will break all code using the secret.
You cannot rename the secret with a name that is already in use.
Do not leave private keys in your code! Leaving them in is a security risk. Either delete the keys from the code after running
updateSecret()
, or pass the parameters in using the Functional Testing tool.
Syntax
function updateSecret(id: string, secret: SecretUpdateInfo): Promise<void>
updateSecret Parameters
NAME
TYPE
DESCRIPTION
The ID of the secret to update.
The information to update the secret with.
Returns
Fulfilled - When the secret is updated. Rejected - Error message.
Return Type:
Was this helpful?
1import wixSecretsBackend from 'wix-secrets-backend';23export function updateName() {4 const id = "b741766c-eead-46fe-8e7f-fd01ff3d6e21";5 const secret = {6 name: "my_new_secret_name"7 };89 return wixSecretsBackend.updateSecret(id, secret)10 .then(() => {11 console.log("Secret name updated");12 })13 .catch((error) => {14 console.error(error);15 })16}
1import wixSecretsBackend from 'wix-secrets-backend';23export function updateMultipleProperties() {4 const id = "b741766c-eead-46fe-8e7f-fd01ff3d6e21";5 const secret = {6 name: "my_new_secret_name",7 description: "New description",8 value: "new.key.44aSQCljxL9FLvTVA.9dKbpwueYoQ8isyQhvun19pOT9gHEdgxam39LJ0Ts70"9 };1011 return wixSecretsBackend.updateSecret(id, secret)12 .then(() => {13 console.log("All secret fields updated");14 })15 .catch((error) => {16 console.error(error);17 });18}