supabase-community / godot-engine.supabase

A lightweight addon which integrates Supabase APIs for Godot Engine out of the box.
MIT License
159 stars 17 forks source link

[BUG] Realtime update events won´t work with auth.uid - checking RLS policy! #68

Open BurSari92 opened 12 months ago

BurSari92 commented 12 months ago

Hi guys,

I think I found an really annoying bug. The code below is only working if I change the RLS policy inside supabase to "read access for everyone". But if i make a standard authentication check policy like "(auth.uid() = user_id)" it won´t work and I won´t get any update informations on client.

Database reading with the "standard auth policy" is working fine, like "read access for everyone policy" does btw. I think the client variable is not passing some auth informations to server probably?

Before executing the function below, the user signes in of course.

var client : RealtimeClient
var channel : RealtimeChannel

func _getChangesFromServer():
    client = Supabase.realtime.client()
    client.connected.connect(Callable(self, "_onConnectedToFriendChat"))
    client.connect_client()

func _onConnectedToFriendChat():
    var userID : String = userData[0]["id"]

    channel = client.channel("public", "friends", "user_id=eq." + userID)
    channel.update.connect(Callable(self,"_onFriendChatUpdate"))
    channel.subscribe()

func _onFriendChatUpdate(old_record : Dictionary, new_record : Dictionary, channel : RealtimeChannel):
    print("New Record updated from ", JSON.stringify(old_record), "to ", JSON.stringify(new_record), " on ", channel.topic)

For now I am using a filter to get only data which the user should have access to ("user_id=eq." + userID) but security-wise it´s a mess..

Hope someone could help out!

ghost commented 9 months ago

The update from this library does not work in general

MaxKablaam commented 9 months ago

I'm having the same bug. If I put my tables RLS read access to public, the realtime works. If not, I get no notifications.