> ## Documentation Index
> Fetch the complete documentation index at: https://docs.fga.dev/llms.txt
> Use this file to discover all available pages before exploring further.

# Managing Group Membership

> Updating a user's membership to a group by adding and removing them from it

In this guide you will learn how to update a user's membership to a group by adding and removing them from it.

**When to use**

Suppose:

* An employee is hired at a company and thus gains access to all of the company's resources.
* An employee quits and thus loses access to all of the company's resources.
* A user joins a GitHub organization and gains access to the organizations private repositories.
* A student graduates from school and loses access to the school's facilities.

These are cases where using group membership can be helpful as you do not need to iterate over all of the group's resources to add or revoke access to particular objects. You can add a relationship tuple indicating that a user belongs to a group, or delete a tuple to indicate that a user is no longer part of the group.

## Before you start

In order to understand this guide correctly you must be familiar with some [Auth0 FGA Concepts](https://docs.fga.dev/fga-concepts.md) and know how to develop the things that we will list below.

<details>
  <summary>
    Assume that you have the following [authorization model](https://docs.fga.dev/fga-concepts.md#what-is-an-authorization-model).\\

    You have two [types](https://docs.fga.dev/fga-concepts.md#what-is-a-type):

    * `org` that can have a `member` relation
    * `document` that can have a `reader` relation.
  </summary>

  Let us also assume that we have an `org` called "contoso" and a `document` called `planning`, and every `member` of that `org` can read the document. That is represented by having the following *[relationship tuple](https://docs.fga.dev/fga-concepts.md#what-is-a-relationship-tuple)* in the store:

  ```json theme={null}
  [
    // Members of the contoso org can read the planning document
    {
      "user": "org:contoso#member",
      "relation": "reader",
      "object": "document:planning"
    }
  ]
  ```

  With the above authorization model and relationship tuples, Auth0 FGA will respond with `{"allowed":false}` when *[check](https://docs.fga.dev/fga-concepts.md#what-is-a-check-request)* is called to see if Anne can read `document:planning`.

  Now let's make Anne a `member` of `org:contoso` by adding another tuple:

  The Auth0 FGA service will now correctly respond with `{"allowed":true}` when check is called to see if Anne can read `document:planning`, but it will still respond with `{"allowed":false}` if we ask the same question for another user called Becky, who is not a member of the group `org:contoso`.

  ### Modeling user groups

  You need to know how to add users to groups and grant groups access to an object. [Learn more →](https://docs.fga.dev/modeling/basics/user-groups.md)

  ### Managing group access

  You need to know how to manage group access to an object. [Learn more →](https://docs.fga.dev/writing-data/managing-group-access.md)

  ### Auth0 FGA concepts

  * A [Type](https://docs.fga.dev/fga-concepts.md#what-is-a-type): a class of objects that have similar characteristics
  * A [User](https://docs.fga.dev/fga-concepts.md#what-is-a-user): an entity in the system that can be related to an object
  * A [Relation](https://docs.fga.dev/fga-concepts.md#what-is-a-relation): is a string defined in the type definition of an authorization model that defines the possibility of a relationship between an object of the same type as the type definition and a user in the system
  * An [Object](https://docs.fga.dev/fga-concepts.md#what-is-an-object): represents an entity in the system. Users' relationships to it can be define through relationship tuples and the authorization model
  * A [Relationship Tuple](https://docs.fga.dev/fga-concepts.md#what-is-a-relationship-tuple): a grouping consisting of a user, a relation and an object stored in Auth0 FGA
</details>

## Step by step

### 01. Revoking group membership

Imagine that every member of `org:contoso` has a `reader` relationship to 1000 documents. Now imagine that `anne` is no longer a member of `org:contoso`, so we want to revoke her access to all those documents, including `document:planning`. To accomplish this, we can simply **delete** the tuple in Auth0 FGA that specifies that Anne is a `member` of `org:contoso`.

### 02. Validating revoked member no longer has access

Once the above relationship tuple is deleted, we can check if Anne can read `document:planning`. Auth0 FGA will return `{ "allowed": false }`.

## Related Sections

Check the following sections for more on how to model group.

[Modeling User Groups
Learn about how to model users and groups.](https://docs.fga.dev/modeling/basics/user-groups.md)

[Managing Group Access
Learn about managing group access.](https://docs.fga.dev/writing-data/managing-group-access.md)
