Skip to main content

unassignUserFromGroup

unassignUserFromGroup function unassigns a user from a group within the RBAC (Role-Based Access Control) system. It takes the userId and groupId as required parameters, which are the IDs of the user and group, respectively. The optional address parameter can be used to specify the address associated with the operation, and the optional seed parameter is used for the mnemonic seed if provided. The function returns a JSON object containing the result of the unassignment operation, with a message property indicating the outcome.

Parameters:

  • userId (string): ID of the user to unassign from the group. This parameter is required.

  • groupId (string): ID of the group from which to unassign the user. This parameter is required.

  • address (Address): address associated with the unassignment operation. This parameter is optional.

  • seed (string): mnemonic seed associated with the unassignment operation. This parameter is optional.

Code example


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

/**
* Unassigns a user from a group within the RBAC system.
* @param {string} userId - The ID of the user to unassign (required).
* @param {string} groupId - The ID of the group from which to unassign the user (required).
* @param {Address} [address] - The address associated with the operation (not required).
* @param {string} [seed] - The mnemonic seed associated with the operation (not required).
* @returns {Promise<Object>} - A promise that resolves to an object containing the result message.
*/
const unassignUserToGroup = async (userId, groupId, seed) => {
const sdkInstance = await Sdk.createInstance({
baseUrl: "wss://wsspc1-qa.agung.peaq.network",
seed,
});

try {
const result = await sdkInstance.rbac.unassignUserFromGroup({
userId,
groupId,
});

return result;
} finally {
await sdkInstance.disconnect();
}
};

// Example usage
const userId = '44759999-az06-2112-7130-b5kk4321';
const groupId = '02709409-kd01-4444-8222-b5zz8512';
const mnemonicSeed = "your_mnemonic_seed_here";

unassignUserToGroup(userId, groupId, mnemonicSeed)
.then((result) => {
console.log(result.message);
})
.catch((error) => {
console.error("Error unassigning user from group:", error);
});


Response object


{
message: "Successfully unassign user: 44759999-az06-2112-7130-b5kk4321 from group: 02709409-kd01-4444-8222-b5zz8512"
}