Teams

Teams are a good way to allow users to share access to resources. For example, in a todo app, a user can create a team for one of their todo lists and invite another user to the team to grant the other user access. You can further give special rights to parts of a team using team roles.

The invited user can accept the invitation to gain access. If the user's ever removed from the team, they'll lose access again.

Create team

For example, we can create a team called teachers with roles maths, sciences, arts, and literature.

The creator of the team is also granted the owner role. Only those with the owner role can invite and remove members.

import { Client, Teams } from "appwrite";

const client = new Client();

const teams = new Teams(client);

client
    .setEndpoint('https://cloud.appwrite.io/v1') // Your API Endpoint
    .setProject('5df5acd0d48c2') // Your project ID
;

const promise = teams.create(
    'teachers',
    'Teachers',
    ['maths', 'sciences', 'arts', 'literature']
);

promise.then(function (response) {
    console.log(response); // Success
}, function (error) {
    console.log(error); // Failure
});

Invite a member

You can invite members to a team by creating team memberships. For example, inviting "David" a math teacher, to the teachers team.

import { Client, Teams } from "appwrite";

const client = new Client();

const teams = new Teams(client);

client
    .setEndpoint('https://cloud.appwrite.io/v1') // Your API Endpoint
    .setProject('5df5acd0d48c2') // Your project ID
;

const promise = teams.createMembership(
    'teachers',
    ["maths"],
    "david@example.com"
    );

promise.then(function (response) {
    console.log(response); // Success
}, function (error) {
    console.log(error); // Failure
});

Permissions

You can grant permissions to all members of a team using the Role.team(<TEAM_ID>) role or individual roles in the team using the Role.team(<TEAM_ID>, [<ROLE_1>, <ROLE_2>, ...]) role.

DescriptionRole
All membersRole.team(<TEAM_ID>)
Select rolesRole.team(<TEAM_ID>, [<ROLE_1>, <ROLE_2>, ...])

Learn more about permissions