supabase / supabase-flutter

Flutter integration for Supabase. This package makes it simple for developers to build secure and scalable products.
https://supabase.com/
MIT License
661 stars 154 forks source link

Invalid API key on sendBroadcastMessage method on realtime. #867

Closed ardainancdev closed 2 months ago

ardainancdev commented 3 months ago

I get this error with the when using the sendBroadcastMessage function, here is my body {"message":"Invalid API key","hint":"Double check your Supabaseanonorservice_roleAPI key."}

My code This is sending a broadcast messages.

void sendBroadcastMessage(
    String chatRoomId,
    TextEditingController textController,
  ) async {
    final message = textController.text;
    if (message.isEmpty) return;
    final channel = supabase.channel('chat_$chatRoomId').subscribe();

    final res = await channel.sendBroadcastMessage(event: 'chat', payload: {
      'message': message,
      'user_id': Supabase.instance.client.auth.currentUser!.id,
      'timestamp': DateTime.now().millisecondsSinceEpoch,
      'message_type': 'text',
    });
    print(res);
  }

res= image

Screenshot of a network debugger. image

Version: dart pub deps


└── supabase_flutter 2.3.4
    ├── supabase 2.0.8
    │   ├── functions_client 2.0.0
    │   ├── gotrue 2.5.1
    │   ├── postgrest 2.1.1
    │   ├── realtime_client 2.0.1
    │   ├── storage_client 2.0.1

flutter --version

Flutter 3.19.3 • channel stable • https://github.com/flutter/flutter.git
Framework • revision ba39319843 (2 weeks ago) • 2024-03-07 15:22:21 -0600
Engine • revision 2e4ba9c6fb
Tools • Dart 3.3.1 • DevTools 2.31.1

Additional context

All functions related to the Supabase are actively working on my project

None of the problems with apiKey and anon are experienced when launching my application, the only problem seems to be this function.