Flutter 异常错误创建 StreamChat 频道
Flutter Exception Error Creating StreamChat channel
您好,我正在尝试使用 StreamChat.io API 构建聊天应用程序,但是当我尝试创建频道时出现此错误 StreamChatNetworkError (StreamChatNetworkError(code: 1000, message: Unauthorised, token not defined))
这是我设置的加入频道的代码
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);
}
}
而且我已经禁用了身份验证检查,所以不需要秘密
在 Stream 团队的帮助下,我发现您需要先建立一个连接的用户才能观看频道
await client.connectUser(
User(id: "john"),
client.devToken('john').rawValue,
);
编辑:上面使用了开发人员令牌(需要禁用身份验证)。在生产环境中,您需要使用 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
之一生成前端令牌
有关连接和身份验证的更多信息:https://getstream.io/chat/docs/flutter-dart/tokens_and_authentication/?language=dart
查看 Stream Chat Flutter getting started tutorial 以获得更多帮助。
您好,我正在尝试使用 StreamChat.io API 构建聊天应用程序,但是当我尝试创建频道时出现此错误 StreamChatNetworkError (StreamChatNetworkError(code: 1000, message: Unauthorised, token not defined))
这是我设置的加入频道的代码
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);
}
} 而且我已经禁用了身份验证检查,所以不需要秘密
在 Stream 团队的帮助下,我发现您需要先建立一个连接的用户才能观看频道
await client.connectUser(
User(id: "john"),
client.devToken('john').rawValue,
);
编辑:上面使用了开发人员令牌(需要禁用身份验证)。在生产环境中,您需要使用 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
之一生成前端令牌有关连接和身份验证的更多信息:https://getstream.io/chat/docs/flutter-dart/tokens_and_authentication/?language=dart
查看 Stream Chat Flutter getting started tutorial 以获得更多帮助。