Sharing files and folders
The secrecyClient.cloud.shareNode
method shares a file or folder in the cloud with a specific Secrecy user, granting them certain access Rights
.
It takes three parameters: nodeId (the ID of the file or folder to be shared), right (the level of access—admin, write, or read), and secrecyUserId (the ID of the user to share with).
cloud.ts
// Rights 'admin' | 'write' | 'read'
import { type Rights } from '@secrecy/lib';
const shareFileOrFolder = async ({
nodeId,
right,
secrecyUserId,
}: {
nodeId: string;
right: Rights;
secrecyUserId: string;
}): Promise<boolean> => {
// First we need to check if the secrecyClient is available
if (!secrecyClient) {
return false;
}
try {
const isShared = await secrecyClient.cloud.shareNode({
rights: right,
userId: secrecyUserId,
nodeId: nodeId,
});
return isShared;
} catch (error) {
console.error(error);
return false;
}
};