Groups as permission scopes

Every CoValue has an owner, which can be a Group or an Account.

You can use a Group to grant access to a CoValue to multiple users. These users can have different roles, such as "writer", "reader" or "admin".

...more docs coming soon

Creating a Group

Here's how you can create a Group.

import { Group } from "jazz-tools"; const group = Group.create({ owner: me });

The Group itself is a CoValue, and whoever owns it is the initial admin.

You typically add members using public sharing or invites. But if you already know their ID, you can add them directly (see below).

Adding group members by ID

You can add group members by ID by using Account.load and Group.addMember.

import { Group, Account } from "jazz-tools"; const group = Group.create({ owner: me }); const bob = await Account.load(bobsID, me, []); group.addMember(bob, "writer");

Note: if the account ID is of type string, because it comes from a URL parameter or something similar, you need to cast it to ID<Account> first:

import { Group, Account, ID } from "jazz-tools"; const bob = await Account.load(bobsID as ID<Account>, me, []); group.addMember(bob, "writer");

...more docs coming soon

Getting the Group of an existing CoValue

You can get the group of an existing CoValue by using coValue._owner.

const group = existingCoValue._owner; const newValue = MyCoMap.create( { color: "red"}, { owner: group } );

Because ._owner can be an Account or a Group, in cases where you specifically need to use Group methods (such as for adding members or getting your own role), you can cast it to assert it to be a Group:

import { Group } from "jazz-tools"; const group = existingCoValue._owner.castAs(Group); group.addMember(bob, "writer"); group.myRole();

...more docs coming soon