0

Hello I'm trying to use StreamChat.io API to build a chat app but when I try to create a channel I get this error StreamChatNetworkError (StreamChatNetworkError(code: 1000, message: Unauthorised, token not defined))

Here is the code I set to join a channel

Future<void> createChannel(BuildContext context) async {
try {
  final currentUser = FirebaseAuth.instance.currentUser;
  final userID = currentUser!.uid;
  final client = StreamChatCore.of(context).client;
  final channel = client.channel("messaging", id: userID, extraData: {
    "name": _name.text.trim(),
  });
  AccountUpdate.storeChannel(channel);
  await channel.watch();
  print("this is the channel output $channel");
} catch (e) {
  print(e);
}

} And I have disabled Auth checks so there is no need for a secret

JoeCodes
  • 35
  • 6

1 Answers1

0

With help from the Stream team, I figured out that you need to establish a connected user first in order to watch a channel

await client.connectUser(
    User(id: "john"),
    client.devToken('john').rawValue,
  );

EDIT: The above makes use of developer tokens (which requires authentication to be disabled). In a production environment you will need to generate frontend tokens using one of Stream's backend clients. Or for development purposes you can use the online token generator https://getstream.io/chat/docs/flutter-dart/token_generator/?language=dart

More info on connections and authentication: https://getstream.io/chat/docs/flutter-dart/tokens_and_authentication/?language=dart

See the Stream Chat Flutter getting started tutorial for more help.

Gordon Hayes
  • 231
  • 1
  • 7
JoeCodes
  • 35
  • 6
  • Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community May 11 '22 at 07:47