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

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}
14
Delete an existing secret (export from backend code)

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