Skip to content

Commit 4fdfbb7

Browse files
authored
add providers (#22)
1 parent b2a6dd8 commit 4fdfbb7

File tree

4 files changed

+50
-29
lines changed

4 files changed

+50
-29
lines changed

addons/supabase/Auth/auth.gd

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ const _invite_endpoint : String = _auth_endpoint+"/invite"
3434
const _reset_password_endpoint : String = _auth_endpoint+"/recover"
3535

3636
var tcp_server : TCP_Server = TCP_Server.new()
37+
var tcp_timer : Timer = Timer.new()
3738

3839
var _config : Dictionary = {}
3940
var _header : PoolStringArray = []
@@ -77,15 +78,11 @@ func sign_in(email : String, password : String = "") -> AuthTask:
7778

7879
# Sign in with a Provider
7980
# @provider = Providers.PROVIDER
80-
func sign_in_with_provider(provider : String) -> AuthTask:
81-
var payload : Dictionary = {}
82-
var auth_task : AuthTask = AuthTask.new(
83-
AuthTask.Task.SIGNIN,
84-
_config.supabaseUrl + _provider_endpoint + "?provider=" + provider,
85-
_header,
86-
payload)
87-
_process_task(auth_task)
88-
return auth_task
81+
func sign_in_with_provider(provider : String, grab_from_browser : bool = true, port : int = 3000) -> void:
82+
OS.shell_open(_config.supabaseUrl + _provider_endpoint + "?provider="+provider)
83+
# ! to be implemented
84+
pass
85+
8986

9087
# If a user is logged in, this will log it out
9188
func sign_out() -> AuthTask:
@@ -177,6 +174,7 @@ func _get_link_response(delta : float) -> void:
177174
var peer : StreamPeer = tcp_server.take_connection()
178175
if peer != null:
179176
var raw_result : String = peer.get_utf8_string(peer.get_available_bytes())
177+
return raw_result
180178
else:
181179
_get_link_response(delta)
182180

@@ -210,8 +208,6 @@ func _on_task_completed(task : AuthTask) -> void:
210208
elif task.data == null:
211209
match task._code:
212210
AuthTask.Task.MAGICLINK:
213-
tcp_server.listen(3000)
214-
_get_link_response(0.5)
215211
emit_signal("magic_link_sent")
216212
AuthTask.Task.RECOVER:
217213
emit_signal("reset_email_sent")
@@ -227,3 +223,8 @@ func _on_task_completed(task : AuthTask) -> void:
227223
emit_signal("error", task.error)
228224

229225

226+
# A timer used to listen through TCP on the redirect uri of the request
227+
func _tcp_stream_timer() -> void:
228+
var peer : StreamPeer = tcp_server.take_connection()
229+
# ! to be implemented
230+
pass

addons/supabase/Database/query.gd

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ func _init():
6464
# Build the query from the scrut
6565
func build_query() -> String:
6666
for key in query_struct:
67+
if query_struct[key].empty(): continue
6768
match key:
6869
"table":
6970
query += query_struct[key]
@@ -249,4 +250,4 @@ func clean() -> void:
249250

250251

251252
func _to_string() -> String:
252-
return "QUERY: " + query
253+
return build_query()

addons/supabase/Realtime/realtime_channel.gd

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ func _init(topic : String, client) -> void:
1414
self.topic = topic
1515
_client = client
1616

17-
func publish(message : Dictionary):
17+
func _publish(message : Dictionary) -> void:
1818
if not subscribed: return
1919
match message.event:
2020
_client.SupabaseEvents.DELETE:
@@ -24,32 +24,37 @@ func publish(message : Dictionary):
2424
_client.SupabaseEvents.INSERT:
2525
emit_signal("insert", message.payload.record, self)
2626
emit_signal("all", message.payload.get("old_record", {}), message.payload.get("new_record", {}), self)
27-
27+
28+
func on(event : String, to : Object, function : String) -> RealtimeChannel:
29+
connect(event, to, function)
30+
return self
2831

29-
func subscribe():
32+
func subscribe() -> RealtimeChannel:
3033
if subscribed:
3134
_client._error("Already subscribed to topic: %s" % topic)
32-
return
35+
return self
3336
_client.send_message({
3437
"topic": topic,
3538
"event": _client.PhxEvents.JOIN,
3639
"payload": {},
3740
"ref": null
3841
})
3942
subscribed = true
43+
return self
4044

4145

42-
func unsubscribe():
46+
func unsubscribe() -> RealtimeChannel:
4347
if not subscribed:
4448
_client._error("Already unsubscribed from topic: %s" % topic)
45-
return
49+
return self
4650
_client.send_message({
4751
"topic": topic,
4852
"event": _client.PhxEvents.LEAVE,
4953
"payload": {},
5054
"ref": null
5155
})
5256
subscribed = false
57+
return self
5358

54-
func remove() -> void:
55-
_client.erase(self)
59+
func close() -> void:
60+
_client._remove_channel(self)

addons/supabase/Realtime/realtime_client.gd

Lines changed: 23 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@ func _init(url : String, apikey : String, timeout : float) -> void:
3131
_db_url = url.replace("http","ws")+"/realtime/v1/websocket"
3232
_apikey = apikey
3333
_heartbeat_timer.set_wait_time(timeout)
34+
_heartbeat_timer.name = "PhxHeartbeat"
35+
name = "RealtimeClient"
3436

3537
func _ready() -> void:
3638
add_child(_heartbeat_timer)
@@ -44,7 +46,7 @@ func _connect_signals() -> void:
4446

4547
func _disconnect_signals() -> void:
4648
_ws_client.disconnect("connection_closed", self, "_closed")
47-
_ws_client.disconnect("connection_error", self, "_closed")
49+
_ws_client.disconnect("connection_error", self, "_error")
4850
_ws_client.disconnect("connection_established", self, "_connected")
4951
_ws_client.disconnect("data_received", self, "_on_data")
5052
_heartbeat_timer.disconnect("timeout", self, "_on_timeout")
@@ -62,6 +64,9 @@ func connect_client() -> int:
6264
func disconnect_client() -> void:
6365
_ws_client.disconnect_from_host(1000, "Disconnection requested from client.")
6466

67+
func remove_client() -> void:
68+
queue_free()
69+
6570
func channel(schema : String, table : String = "", col_value : String = "") -> RealtimeChannel:
6671
var topic : String = _build_topic(schema, table, col_value)
6772
var channel : RealtimeChannel = get_channel(topic)
@@ -81,39 +86,48 @@ func _build_topic(schema : String, table : String = "", col_value : String = "")
8186
func _add_channel(channel : RealtimeChannel) -> void:
8287
channels.append(channel)
8388

89+
func _remove_channel(channel : RealtimeChannel) -> void:
90+
channels.erase(channel)
91+
8492
func _connected(proto = ""):
8593
emit_signal("connected")
8694
set_process(true)
8795

8896
func _closed(was_clean : bool = false):
89-
emit_signal("disconnected")
97+
channels = []
9098
_disconnect_signals()
99+
emit_signal("disconnected")
91100
set_process(false)
92101

93-
func _error(msg : String = "") :
102+
func _error(msg : String = "") -> void:
94103
emit_signal("error", msg)
95104

96105
func _on_data() -> void:
97106
var data : Dictionary = get_message(_ws_client.get_peer(1).get_packet())
107+
print(data)
98108
match data.event:
99109
PhxEvents.REPLY:
100110
if _check_response(data) == 0:
101-
print("Received reply = "+to_json(data))
111+
pass
112+
# print("Received reply = "+to_json(data))
102113
PhxEvents.JOIN:
103114
if _check_response(data) == 0:
104-
print("Joined topic '%s'" % data.topic)
115+
pass
116+
# print("Joined topic '%s'" % data.topic)
105117
PhxEvents.LEAVE:
106118
if _check_response(data) == 0:
107-
print("Left topic '%s'" % data.topic)
119+
pass
120+
# print("Left topic '%s'" % data.topic)
108121
PhxEvents.CLOSE:
109-
print("Channel closed.")
122+
pass
123+
# print("Channel closed.")
110124
PhxEvents.ERROR:
111125
emit_signal("error", data.payload)
112126
SupabaseEvents.DELETE, SupabaseEvents.INSERT, SupabaseEvents.UPDATE:
113-
print("Received %s event..." % data.event)
127+
# print("Received %s event..." % data.event)
114128
var channel : RealtimeChannel = get_channel(data.topic)
115129
if channel != null:
116-
channel.publish(data)
130+
channel._publish(data)
117131

118132
func get_channel(topic : String) -> RealtimeChannel:
119133
for channel in channels:

0 commit comments

Comments
 (0)