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 (dashboard page code)

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}
17
Update a single property of a secret (export from backend code)

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

Copy Code
1import { Permissions, webMethod } from 'wix-web-module';
2import { secrets } from 'wix-secrets-backend.v2';
3
4export const updateMultipleProperties = webMethod(Permissions.Anyone, () => {
5 const id = 'b741766c-eead-46fe-8e7f-fd01ff3d6e21';
6 const secret = {
7 name: 'my_new_secret_name',
8 description: 'New description',
9 value: 'new.key.44aSQCljxL9FLvTVA.9dKbpwueYoQ8isyQhvun19pOT9gHEdgxam39LJ0Ts70'
10 };
11
12 return secrets.updateSecret(id, secret)
13 .then(() => {
14 console.log('All secret fields updated');
15 })
16 .catch((error) => {
17 console.error(error);
18 });
19});
20