Documentation
Client SDK
Stop sharing

Stop sharing files and folders

The method secrecyClient.cloud.deleteNodeSharing attempts to stop sharing a file or folder with a specified user or group. It takes two parameters: nodeId (the ID of the file or folder to stop sharing) and destPubKey (the public key of the user or group to stop sharing with).

cloud.ts
const stopSharingFileOrFolder = async ({
  nodeId,
  secrecyUserId,
}: {
  nodeId: string;
  secrecyUserId: string;
}): Promise<boolean> => {
  // First we need to check if the secrecyClient is available
  if (!secrecyClient) {
    return false;
  }
 
  try {
    // the sharing is identified by the public key of the user it was shared to
    const destPubKey = await secrecyClient.app.userPublicKey(secrecyUserId);
 
    const isSharingStop = await secrecyClient.cloud.deleteNodeSharing({
      nodeId,
      destPubKey,
    });
 
    return isSharingStop;
  } catch (error) {
    console.error(error);
    return false;
  }
};

Leave a sharing

The method secrecyClient.cloud.leaveNodeSharing is the counterpart used by the recipient of a sharing to remove their own access. It takes the nodeId and the sharedByPubKey, the public key of the user who shared the node. The sharedByPubKey of a shared node is available on its accesses.

cloud.ts
const leaveSharedNode = async ({
  nodeId,
  sharedByPubKey,
}: {
  nodeId: string;
  sharedByPubKey: string;
}): Promise<boolean> => {
  // First we need to check if the secrecyClient is available
  if (!secrecyClient) {
    return false;
  }
 
  try {
    const hasLeft = await secrecyClient.cloud.leaveNodeSharing({
      nodeId,
      sharedByPubKey,
    });
 
    return hasLeft;
  } catch (error) {
    console.error(error);
    return false;
  }
};