Search.../

deleteSecret( )

Deletes an existing secret by ID.

Description

The deleteSecret() function returns a Promise that resolves when a secret from the Secrets Manager is deleted. You can retrieve the id parameter using the listSecretInfo() function. Note that the ID used here is the ID retrieved from listSecretInfo(), not the secret name used by getSecret().

Note: Deleting a secret is irreversible and will break all code using the secret.

Syntax

function deleteSecret(id: string): Promise<void>

deleteSecret Parameters

NAME
TYPE
DESCRIPTION
id
string

The ID of the secret to be deleted.

Returns

Fulfilled - When the secret is deleted from the Secrets Manager. Rejected - Error message.

Return Type:

Promise<void>

Was this helpful?

Delete an existing secret

Copy Code
1import { Permissions, webMethod } from 'wix-web-module';
2import wixSecretsBackend from 'wix-secrets-backend';
3
4export const deleteMySecret = webMethod(Permissions.Anyone, () => {
5 const id = "b741766c-eead-46fe-8e7f-fd01ff3d6e21";
6
7 return wixSecretsBackend.deleteSecret(id)
8 .then(() => {
9 console.log("Secret deleted");
10 })
11 .catch((error) => {
12 console.error(error);
13 });
14});
Retrieve an ID and delete a secret

This example demonstrates how to delete the first secret stored in the Secrets Manager. First we retrieve the ID of the secret using the listSecretInfo() function. Then we delete the secret using the retrieved ID.

Copy Code
1import { Permissions, webMethod } from 'wix-web-module';
2import wixSecretsBackend from 'wix-secrets-backend';
3
4export const deleteFirstSecret = webMethod(Permissions.Anyone, () => {
5 return wixSecretsBackend.listSecretInfo()
6 .then((secrets) => {
7 return wixSecretsBackend.deleteSecret(secrets[0].id);
8 })
9 .then(() => {
10 console.log("Secret deleted");
11 })
12 .catch((error) => {
13 console.error(error);
14 });
15});