Search.../

updateSecret( )

Developer Preview

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 fields. Only fields passed in the secret object will be updated. All other properties will remain unchanged.

You can retrieve the _id parameter from the listSecretInfo() function. The secret _id is different from the secret name used by the getSecretValue() function.

Notes:

  • Changing a secret's name or value will break all code using the secret.
  • You can't rename the secret with a name of an existing secret.
  • Don't leave private keys in your code! Leaving them in is a security risk. Make sure to delete the keys from the code after running updateSecret().
Admin Method

This function requires elevated permissions to run. This function is not universal and runs only on the backend.

Syntax

function updateSecret(_id: string, secret: Secret): Promise<void>

updateSecret Parameters

NAME
TYPE
DESCRIPTION
_id
string

The unique ID of the secret to be updated.

secret
Secret

The secret fields to update.

Returns

Fulfilled - When the secret is updated. Rejected - Error message.

Return Type:

Promise<
void
>

Was this helpful?

Update a single property of a secret

Copy Code
1import { secrets } from 'wix-secrets-backend.v2';
2
3export function updateName() {
4 const id = 'b741766c-eead-46fe-8e7f-fd01ff3d6e21';
5 const secret = {
6 name: 'my_new_secret_name'
7 };
8
9 return secrets.updateSecret(id, secret)
10 .then(() => {
11 console.log('Secret name updated');
12 })
13 .catch((error) => {
14 console.error(error);
15 })
16}
Update multiple properties of a secret

Copy Code
1import { secrets } from 'wix-secrets-backend.v2';
2
3export 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 };
10
11 return secrets.updateSecret(id, secret)
12 .then(() => {
13 console.log('All secret fields updated');
14 })
15 .catch((error) => {
16 console.error(error);
17 });
18}