Introduction
Read the user groups of your project: the flat list, the top level, a single group, or the children of one.
More information about the module's user interface https://doc.oneentry.cloud/docs/category/users
🎯 What does this module do?
The UserGroups module lets you read the groups your visitors belong to. A group decides what a visitor may see, and groups form a tree — a group can have a parent and children.
Groups are created and nested in the OneEntry admin panel; the SDK is read-only and only fetches them. Every project has at least the guest group, which is where an unauthenticated visitor lands.
🚀 Quickstart
Initialize the module from defineOneEntry:
const { UserGroups } = defineOneEntry( "your-project-url", { "token": "your-app-token" });
Read the whole list, or start at the top of the tree:
// Every group, flat, regardless of nesting.
const groups = await UserGroups.getUserGroups();
// Only the groups without a parent.
const roots = await UserGroups.getRootUserGroups();
roots.forEach((group) => {
console.log(group.identifier, group.localizeInfos.title);
});
🌳 Walking the tree
Read the children of a group by the marker of the parent, not by parentId:
const children = await UserGroups.getChildUserGroupsByMarker('guest');
A group with no children returns an empty array.
⚠️ childrenCount is a string
The API sends childrenCount as a string, not a number:
{ "identifier": "guest", "childrenCount": "0" }
Compare it as a string, or convert it yourself:
if (Number(group.childrenCount) > 0) {
const children = await UserGroups.getChildUserGroupsByMarker(group.identifier);
}
📋 Methods
| Method | What it returns |
|---|---|
getUserGroups() | Every group as a flat array |
getRootUserGroups() | Groups without a parent |
getUserGroupById(id) | One group by its identifier |
getUserGroupByMarker(marker) | One group by its marker |
getChildUserGroupsByMarker(marker) | Children of the given group |