deleteSecret( )
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.
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
The unique ID of the secret to be deleted.
Returns
Fulfilled - When the secret is successfully deleted. Rejected - Error message.
Return Type:
Was this helpful?
1import { secrets } from 'wix-secrets-backend.v2';23export function deleteMySecret() {4 const id = "b741766c-eead-46fe-8e7f-fd01ff3d6e21";56 return secrets.deleteSecret(id)7 .then(() => {8 console.log("Secret deleted");9 })10 .catch((error) => {11 console.error(error);12 });13}14
1import { Permissions, webMethod } from 'wix-web-module';2import { secrets } from 'wix-secrets-backend.v2';34export const deleteMySecret = webMethod(Permissions.Anyone, () => {5 const id = "b741766c-eead-46fe-8e7f-fd01ff3d6e21";67 return secrets.deleteSecret(id)8 .then(() => {9 console.log("Secret deleted");10 })11 .catch((error) => {12 console.error(error);13 });14});15
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.
1import { Permissions, webMethod } from 'wix-web-module';2import { secrets } from 'wix-secrets-backend.v2';34export 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