Search.../

deleteSecret( )

Developer Preview

Deletes an existing secret by ID.

Description

The deleteSecret() function returns a Promise that resolves when the secret is deleted. You can retrieve the secret _id using the listSecretInfo() function.

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

Admin Method

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

Syntax

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

deleteSecret Parameters

NAME
TYPE
DESCRIPTION
_id
string

The unique ID of the secret to be deleted.

Returns

Fulfilled - When the secret is successfully deleted. Rejected - Error message.

Return Type:

Promise<
void
>

Was this helpful?

Delete an existing secret

Copy Code
1import { secrets } from 'wix-secrets-backend.v2';
2
3export function deleteMySecret() {
4 const id = "b741766c-eead-46fe-8e7f-fd01ff3d6e21";
5
6 return secrets.deleteSecret(id)
7 .then(() => {
8 console.log("Secret deleted");
9 })
10 .catch((error) => {
11 console.error(error);
12 });
13}
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 { secrets } from 'wix-secrets-backend.v2';
2
3export function deleteFirstSecret() {
4 return secrets.listSecretInfo()
5 .then((secrets) => {
6 return secrets.deleteSecret(secrets[0].id);
7 })
8 .then(() => {
9 console.log('Secret deleted');
10 })
11 .catch((error) => {
12 console.error(error);
13 });
14}
15