@archon-inc/sdk
Version:
Integrate easily to our government platform using this SDK. More info on https://archon.inc/sdk
17 lines (16 loc) • 605 B
JavaScript
import { Archon } from "../Archon.js";
/**
* Given a user or user id, return the roles the user has.
*
* **Warning:** Provides one layer deep of parents for each role, but no further.
* @param user The user to get the roles for.
* @returns A list of roles the user has.
*/
export default async function getRoles(user) {
const userId = typeof user === "string" ? user : user.id;
const response = await Archon.request(`/policy/roles/${userId}`, "GET");
if (response.status !== 200) {
throw new Error(`Failed to retrieve roles for user ${user}.`);
}
return response.data;
}