unassignPermissionToRole
unassignPermissionToRole
function is used to unassign a permission from a role within the Role-Based Access Control (RBAC) system. This function returns JSON object with role and permission IDs.
Parameters:
permissionId (string, required)
: ID of the permission to be unassigned.roleId (string, required)
: ID of the role from which to unassign the permission.address (Address, optional)
: address associated with the operation.seed (string, optional)
: mnemonic seed.
Code example
import { Sdk } from "@peaq-network/sdk";
/**
* Unassigns a permission from a role within the Role-Based Access Control (RBAC) system.
* @param {string} permissionId - The ID of the permission to be unassigned (required).
* @param {string} roleId - The ID of the role from which to unassign the permission (required).
* @param {Address} [address] - The address associated with the operation (not required).
* @param {string} [seed] - The mnemonic seed (not required).
* @returns {Promise<Object>} - A promise that resolves to an object containing a message.
*/
const unassignPermissionToRole = async (permissionId, roleId, seed) => {
const sdkInstance = await Sdk.createInstance({
baseUrl: "wss://wss-async.agung.peaq.network",
seed,
});
try {
await sdkInstance.connect();
const result = await sdkInstance.rbac.unassignPermissionToRole({
permissionId: permissionId,
roleId: roleId,
});
return result;
} finally {
await sdkInstance.disconnect();
}
};
// Example usage
const permissionId = "18709409-bc06-4444-2222-b4zz0000";
const roleId = "78709009-cf06-4224-8632-b5ee8512";
const seed = "your-seed-phrase";
unassignPermissionToRole(permissionId, roleId, seed)
.then((result) => {
console.log("Unassigned permission:", result.message);
})
.catch((error) => {
console.error("Error unassigning permission:", error);
});
Response object
{
message: "Successfully unassign role: 78709009-cf06-4224-8632-b5ee8512 from permission: 18709409-bc06-4444-2222-b4zz0000"
}