Help & Support

Join Groups

This guide will help you manage Group membership on Lens.

Join a Group

To join a Group, follow these steps.

You MUST be authenticated as Account Owner or Account Manager to join a Group.

1

Check Group Rules

First, inspect the group.operations.canJoin field to determine whether the logged-in Account is allowed to join. Some Groups may have restrictions on who can join them.

Check Rules
switch (group.operations.canJoin.__typename) {  case "GroupOperationValidationPassed":    // Joining the group is allowed    break;
  case "GroupOperationValidationFailed":    // Joinin the group is not allowed    console.log(group.operations.canJoin.reason);    break;
  case "GroupOperationValidationUnknown":    // Validation outcome is unknown    break;}

Where:

  • GroupOperationValidationPassed: The logged-in Account can join the Group.

  • GroupOperationValidationFailed: Joining the Group is not allowed. The reason field explains why, and unsatisfiedRules lists the unmet requirements.

  • GroupOperationValidationUnknown: The Group has one or more unknown rules requiring ad-hoc verification. The extraChecksRequired field provides the addresses and configurations of these rules.

Treat the GroupOperationValidationUnknown as failed unless you intend to support the specific rules. See Group Rules for more information.

2

Join the Group

Next, if allowed, join the Group.

Use the joinGroup action to join a Group with the logged-in account.

You MUST be authenticated as Account Owner or Account Manager to make this request.

Example
import { evmAddress } from "@lens-protocol/client";import { joinGroup } from "@lens-protocol/client/actions";
const result = await joinGroup(sessionClient, { group: evmAddress("0x1234") });

3

Handle Result

Finally, handle the result using the adapter for the library of your choice:

import { handleOperationWith } from "@lens-protocol/client/viem";
// …
const result = await joinGroup(sessionClient, {  group: evmAddress("0x1234"),}).andThen(handleOperationWith(walletClient));

See the Transaction Lifecycle guide for more information on how to determine the status of the transaction.

Leave a Group

To leave a Group, follow these steps.

You MUST be authenticated as Account Owner or Account Manager to leave a Group.

1

Check Group Rules

First, inspect the group.operations.canLeave field to determine whether the logged-in Account is allowed to leave. Some Groups may have restrictions on who can leave them.

Check Rules
switch (group.operations.canLeave.__typename) {  case "GroupOperationValidationPassed":    // Leaving the group is allowed    break;
  case "GroupOperationValidationFailed":    // Leaving the group is not allowed    console.log(group.operations.canLeave.reason);    break;
  case "GroupOperationValidationUnknown":    // Validation outcome is unknown    break;}

Where:

  • GroupOperationValidationPassed: The logged-in Account can leave the Group.

  • GroupOperationValidationFailed: Leaving the Group is not allowed. The reason field explains why, and unsatisfiedRules lists the unmet requirements.

  • GroupOperationValidationUnknown: The Group has one or more unknown rules requiring ad-hoc verification. The extraChecksRequired field provides the addresses and configurations of these rules.

Treat the GroupOperationValidationUnknown as failed unless you intend to support the specific rules. See Group Rules for more information.

2

Leave a Group

Next, if allowed, leave the Group.

Use the leaveGroup action to leave a Group with the logged-in account.

You MUST be authenticated as Account Owner or Account Manager to make this request.

Example
import { evmAddress } from "@lens-protocol/client";import { leaveGroup } from "@lens-protocol/client/actions";
const result = await leaveGroup(sessionClient, { group: evmAddress("0x1234") });

3

Handle Result

Finally, handle the result using the adapter for the library of your choice:

import { handleOperationWith } from "@lens-protocol/client/viem";
// …
const result = await leaveGroup(sessionClient, {  account: evmAddress("0x1234"),}).andThen(handleOperationWith(walletClient));

See the Transaction Lifecycle guide for more information on how to determine the status of the transaction.