Skip to main content

fetchUserPermissions

fetchUserPermissions function fetches the permissions associated with a user from the Role-Based Access Control (RBAC) system. This function returns a JSON object with permissions info.

Parameters:

  • owner (required): address of the owner of the permissions. This is typically the address of the user who is associated with the permissions.

  • userId (required): ID of the user for whom you want to fetch permissions. This parameter specifies which user's permissions you are retrieving.

Code example


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

/**
* Fetches the permissions associated with a user from the Role-Based Access Control (RBAC) system.
* @param {Address} owner - The address of the owner of the permissions (required).
* @param {string} userId - The ID of the user for whom to fetch permissions (required).
* @returns {Promise<Array<Object>>} - A promise that resolves to an array of objects containing fetched permission details.
*/
const fetchUserPermissions = async (owner, userId) => {
const sdkInstance = await Sdk.createInstance({
baseUrl: "wss://wsspc1-qa.agung.peaq.network",
});

try {
const permissions = await sdkInstance.rbac.fetchUserPermissions({
owner,
userId,
});

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

// Example usage
const ownerAddress = "5GsA2xjSBY6DhpTGKKdJ4BjUYpbBaP5wxZnvBoHSytURn6N2";
const userId = "44759999-az06-2112-7130-b5kk4321";

fetchUserPermissions(ownerAddress, userId)
.then((permissions) => {
console.log("Fetched User Permissions:", permissions);
})
.catch((error) => {
console.error("Error fetching user permissions:", error);
});


Response object

[
{
"id": "18709409-bc06-4444-2222-b4zz0000",
"name": "myPermission",
"enable": true
}
]