Block Profiles

Learn how to block Profiles and manage blocked ones.


You must be authenticated with the Profile you intend manage blocked profiles for. See Profile Login for more information.

Users can block profiles with which they do not wish to interact. This action has two main effects:

  1. Blocking a profile affects some operations that both the blocked profile and the blocking profile can perform. Specifically:

    • The blocked profile cannot follow the blocking profile. If they were already following at the time they were blocked, they will be automatically unfollowed. The blocking profile on the other hand can still follow the blocked profile.

    • Neither the blocked profile nor the blocking profile can reference each other's content, meaning they cannot comment, mirror, or quote publications from the other profile.

    • Neither the blocked profile nor the blocking profile can execute Open Actions or Collect Actions on each other's publications.

    • The blocked profile cannot longer react to the blocking profile's publications.

  2. The Lens API marks blocked profiles as such whenever they are returned in a response.

It's the responsibility of consumer apps to honor this flag by hiding and/or disabling interactions with blocked profiles.


Detect Blocked Profiles

Blocked profiles are marked as such wherever they appear.

The profile.operations property provides information about the actions that the logged-in profile has performed or can perform on the given profile, including the blocked status.

import { usePublication } from "@lens-protocol/react-web";
// ...
const { data, error, loading } = useProfile({  forHandle: "lens/brainjammer",});
// ...
console.log(data?.operations);

Specifically:

  • operations.isBlockedByMe.value is a boolean that indicates if the logged-in profile has blocked the given profile.

  • operations.isBlockedByMe.isFinalisedOnchain is a boolean that shows if the value of operations.isBlockedByMe.value is finalized on-chain or it has been optimistically updated.

  • operations.canBlock is a boolean that signifies if the logged-in profile can block the given profile. This could be false if the logged-in profile has already blocked the given profile, or if a pending block operation is not yet finalized on-chain.

  • operations.canUnblock is a boolean that indicates if the logged-in profile can unblock the given profile. This could be false if the logged-in profile has not blocked the given profile, or if a pending unblock operation is not yet finalized on-chain.

Block a Profile

In this section, you will learn how to block a Lens Profile.

The useBlockProfiles hook allows you to block one or more Lens Profiles.

Available in @lens-protocol/react-web and @lens-protocol/react-native

The hook choose the Signless Experience when possible; otherwise, it will fall back to a signed experience.

Combine this with the operations object to control the UI and prevent blocking a profile that is already blocked or has a pending unblock operation.

import { Profile, useBlockProfiles } from '@lens-protocol/react-web';
export function BlockButton({ profile }: { profile: Profile }) {  const { execute, loading } = useBlockProfiles();
  const block = async () => {    if (profile.operations.isBlockedByMe.isFinalisedOnchain === false) {      window.alert(        'You cannot unblock this profile until the pending operation is finalised onchain',      );      return;    }
    const result = await execute({ profiles: [profile] });
    if (result.isFailure()) {      window.alert(result.error.message);      return;    }
    const completion = await result.value.waitForCompletion();
    if (completion.isFailure()) {      window.alert(completion.error.message);      return;    }
    window.alert('Blocked successfully');  };
  if (profile.operations.isBlockedByMe.value) {    return <p>Already blocked</p>;  }
  if (!profile.operations.canBlock) {    return <p>Cannot block</p>;  }
  return (    <button onClick={block} disabled={loading}>      Block    </button>  );}

List Blocked Profiles

In this section, you will learn how to retrieve a list of profiles that the logged-in Profile has blocked.

Use the useBlockedProfiles hook to retrieve all the profiles blocked by the authenticated Profile.

Available in @lens-protocol/react-web and @lens-protocol/react-native

import { useBlockedProfiles } from '@lens-protocol/react-web';
function BlockedProfiles() {  const { data, loading, error } = useBlockedProfiles();
  if (loading) return <p>Loading...</p>;
  if (error) return <p>Error: {error.message}</p>;
  if (data.length === 0) return <p>No blocked profiles found</p>;
  return (    <ul>      {data.map((profile) => (        <li key={profile.id}>{profile.handle?.fullHandle ?? profile.id}</li>      ))}    </ul>  );}

The hook yields a PaginatedReadResult<Profile[]>. For more information on pagination, refer to this guide.

Unblock a Profile

In this section, you will learn how to unblock a Lens Profile.

The useUnblockProfiles hook allows you to unblock one or more Lens Profiles.

Available in @lens-protocol/react-web and @lens-protocol/react-native

The hook choose the Signless Experience when possible; otherwise, it will fall back to a signed experience.

Combine this with the operations object to control the UI and prevent unblocking a profile that is not blocked or has a pending block operation.

import { Profile, useBlockProfiles } from '@lens-protocol/react-web';
export function UnblockButton({ profile }: { profile: Profile }) {  const { execute, loading } = useUnblockProfiles();
  const unblock = async () => {    if (profile.operations.isBlockedByMe.isFinalisedOnchain === false) {      window.alert(        'You cannot unblock this profile until the pending operation is finalised onchain',      );      return;    }    const result = await execute({ profiles: [profile] });
    if (result.isFailure()) {      window.alert(result.error.message);      return;    }
    const completion = await result.value.waitForCompletion();
    if (completion.isFailure()) {      window.alert(completion.error.message);      return;    }
    window.alert('Unblocked successfully');  };
  if (!profile.operations.isBlockedByMe.value) {    return <p>Not blocked</p>;  }
  if (!profile.operations.canUnblock) {    return <p>Cannot unblock</p>;  }
  return (    <button onClick={unblock} disabled={loading}>      Unblock    </button>  );}

That's it—you now have a solid understanding of how to manage blocking and unblocking of profiles for your users.