Skip to main content

unassignRoleToUser

The unassignRoleToUser function allows to unassign a role from a specific user within the network's RBAC system. This function returns a JSON object with role and user IDs.

Parameters:

  • userId (type: string, required): ID of the user from which the role should be unassigned.

  • roleId (type: string, required): ID of the role that needs to be unassigned.

  • address (type: address, optional): address of the entity initiating the request. This parameter is optional and can be used for transaction signing.

  • seed (type: string, optional): seed used for transaction signing. This parameter is optional and provides an alternative way for transaction signing.

Code example


import { Sdk } from "@peaq-network/sdk";

/**
* Unassigns a role from a user in the peaq network's RBAC system.
* @param {string} userId - The ID of the user from whom the role should be unassigned.
* @param {string} roleId - The ID of the role to be unassigned.
* @param {string} [address] - The address of the entity initiating the request (optional).
* @param {string} [seed] - The seed for transaction signing (optional).
* @returns {Promise<object>} - A promise that resolves when the role is successfully unassigned.
*/
const unassignRoleToUser = async (userId, roleId, seed) => {
const sdkInstance = await Sdk.createInstance({
baseUrl: "wss://wsspc1-qa.agung.peaq.network",
seed
});

try {
const result = await sdkInstance.rbac.unassignRoleToUser({
roleId,
userId
});
return result
} finally {
await sdkInstance.disconnect();
}
};

// Example usage
const userId = "44759999-az06-2112-7130-b5kk4321";
const roleId = "78709009-cf06-4224-8632-b5ee8512";
const seed = "your-seed-phrase";
unassignRoleToUser(userId, roleId, seed)
.then((result) => {
console.log(result.message);
})
.catch((error) => {
console.error(`Error unassigning role from user: ${error}`);
});


Response object


{
message: "Successfully unassign role: 78709009-cf06-4224-8632-b5ee8512 from user: 44759999-az06-2112-7130-b5kk4321"
}