Skip to content

User is not allowed to perform action ReadChannel #2294

Open
@qu0cquyen

Description

@qu0cquyen

I try to use channel.removeMembers in order to leave a channel.

The current flow is:
Channel List -> Channel Page (Message Screen) -> Open a dialog -> Leave channel

However, right after invoking the leave action, I’m seeing a User is not allowed to perform action ReadChannel in scope exception.

From what I’ve gathered, once the API removes the user, they instantly lose any permissions to read or modify the channel. But because the channel’s state hasn’t fully updated yet—and it still attempts to reload the latest message—the SDK triggers a 403 error due to unauthorized access.

I'm wondering if there is any ways to stop the channel from query the new messages. I've been trying to use stopWatching as well but with no success on stoping the channel from getting the new messages.

My current implementation for leaving a channel:

 Future<bool> _handleLeaveChannel({required User currentUser}) async {
    try {

      await arg.removeMembers(
          // arg.id ?? '', arg.type,
          [currentUser.id],
          message: Message(
            text: '**${currentUser.name}** left the group',
            extraData: const {
              'custom_fields': {'muted_notification': true}
            },
          ));

      final rootContext = rootNavigatorKey.currentState?.context;
      if (rootContext == null) return false;

      if (!rootContext.mounted) return false;
      GoRouter.of(rootContext).popUntil(RouteName.chat.path);

      return true;
    } catch (exception) {
      await Sentry.captureException(
          '[_handleLeaveChannel] throws exception: ${exception.toString()} - $_logName');
      return false;
    }
  }

Exception is thrown:

[App] Exception: StreamChatNetworkError(code: 17, message: GetOrCreateChannel failed with error: "channel "team:xxxxxxx" is disabled", statusCode: 403, data: ErrorResponse(code: 17, message: GetOrCreateChannel failed with error: "channel "team:xxxxxxxx" is disabled", statusCode: 403, moreInfo: https://getstream.io/chat/docs/api_errors_response)) with trace #0      StreamHttpClient.post (package:stream_chat/src/core/http/stream_http_client.dart:152)
I/flutter (28101): 💡 <asynchronous suspension>
I/flutter (28101): 💡 #1      ChannelApi.queryChannel (package:stream_chat/src/core/api/channel_api.dart:36)
I/flutter (28101): 💡 <asynchronous suspension>
I/flutter (28101): 💡 #2      Channel.query (package:stream_chat/src/client/channel.dart:1766)
I/flutter (28101): 💡 <asynchronous suspension>
I/flutter (28101): 💡 #3      StreamChannelState._queryAtMessage (package:stream_chat_flutter_core/src/stream_channel.dart:311)
I/flutter (28101): 💡 <asynchronous suspension>

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions