@@ -49,8 +49,6 @@ var _bearer : PoolStringArray = ["Authorization: Bearer %s"]
49
49
var _auth : String = ""
50
50
var _expires_in : float = 0
51
51
52
- var _pooled_tasks : Array = []
53
-
54
52
var client : SupabaseUser
55
53
56
54
func _init (conf : Dictionary , head : PoolStringArray ) -> void :
@@ -148,11 +146,12 @@ func verify_otp(phone : String, token : String) -> AuthTask:
148
146
149
147
150
148
# Sign in as an anonymous user
151
- func sign_in_anonymous () -> void :
152
- if _auth != "" : return
153
- _auth = _config .supabaseKey
154
- _bearer [0 ] = _bearer [0 ] % _auth
155
- emit_signal ("signed_in" )
149
+ func sign_in_anonymous () -> AuthTask :
150
+ if _auth != "" : return _check_auth ()
151
+ var auth_task : AuthTask = AuthTask .new (AuthTask .Task .SIGNINANONYM , "" , [])
152
+ auth_task .user = SupabaseUser .new ({user = {}, access_token = _config .supabaseKey })
153
+ _process_task (auth_task , true )
154
+ return auth_task
156
155
157
156
158
157
# [ CURRENTLY UNSUPPORTED ]
@@ -261,16 +260,19 @@ func _get_link_response(delta : float) -> void:
261
260
262
261
263
262
# Process a specific task
264
- func _process_task (task : AuthTask ) -> void :
265
- var httprequest : HTTPRequest = HTTPRequest .new ()
266
- add_child (httprequest )
263
+ func _process_task (task : AuthTask , _fake : bool = false ) -> void :
267
264
task .connect ("completed" , self , "_on_task_completed" )
268
- task .push_request (httprequest )
269
- _pooled_tasks .append (task )
265
+ if _fake :
266
+ yield (get_tree ().create_timer (0.5 ), "timeout" )
267
+ task .complete (task .user , task .data , task .error )
268
+ else :
269
+ var httprequest : HTTPRequest = HTTPRequest .new ()
270
+ add_child (httprequest )
271
+ task .push_request (httprequest )
270
272
271
273
272
274
func _on_task_completed (task : AuthTask ) -> void :
273
- task ._handler .queue_free ()
275
+ if task . _handler != null : task ._handler .queue_free ()
274
276
if task .user != null :
275
277
client = task .user
276
278
_auth = client .access_token
@@ -291,6 +293,8 @@ func _on_task_completed(task : AuthTask) -> void:
291
293
emit_signal ("token_refreshed" , client )
292
294
AuthTask .Task .VERIFYOTP :
293
295
emit_signal ("otp_verified" )
296
+ AuthTask .Task .SIGNINANONYM :
297
+ emit_signal ("signed_in_anonyous" )
294
298
refresh_token ()
295
299
elif task .data == null :
296
300
match task ._code :
@@ -308,7 +312,6 @@ func _on_task_completed(task : AuthTask) -> void:
308
312
_expires_in = 0
309
313
elif task .error != null :
310
314
emit_signal ("error" , task .error )
311
- _pooled_tasks .erase (task )
312
315
313
316
# A timer used to listen through TCP on the redirect uri of the request
314
317
func _tcp_stream_timer () -> void :
0 commit comments