supabase-community / godot-engine.supabase

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

4.x patches #52

Closed stmn closed 1 year ago

stmn commented 1 year ago
  1. Restored error type.

Reason:

func _on_auth_error(error : SupabaseAuthError):
    get_tree().call_group("loading_scene", "set_loading")
    match error.type :
        "invalid_grant":
            sign_up(mail ,pwd)
  1. Fixed responses without body

Reason:

  1. Added missing awaits

Reason:

# log_screen.gd
func sign_in(email : String, password : String):
    Supabase.auth.sign_in(email, password)
    error_lbl.hide()
# main.gd
func _ready():
    Supabase.auth.connect("signed_in", _on_signed)

And that _on_signed is not executed. These awaits makes that sign in is working properly and _on_signed is executed. It fix only GDScript style, JS style don't need that fix.

Looks like example from readme.md not working also without that awaits.

func _ready():
    Supabase.auth.signed_in.connect(_on_signed_in)
    Supabase.auth.sign_in(
        "user@supabase.email",
        "userpwd"
    )

func _on_signed_in(user: SupabaseUser) -> void:
    print(user)
stmn commented 1 year ago

Sorry, that 'sign in' problem should be fixed better. I'm looking for better way.

fenix-hub commented 1 year ago

Hi @stmn thanks for all your contributions! The issue with the tasks routines not working with the gdscript style is that since latest betas of Godot 4.0 RefCounted classes are handled differently. Eventually any reference to the BaseTask is lost and the task is not processed anymore, so the signal will httprequest.completed signal will never be executed. In my opinion there's no necessity to change the codebase for now, returning a Signal (which will never be directly used), or adding the await in the inner functions (since this will force asynchronous calls to be synchronous anyway). Instead manually referencing and unreferencing should work.

# base_task.gd

func push_request(httprequest : HTTPRequest) -> void:
+   reference()
    httprequest.request_completed.connect(_on_task_completed.bind(httprequest))
    httprequest.request(_endpoint, _headers, true, _method, _payload)

func _on_task_completed(result : int, response_code : int, headers : PackedStringArray, body : PackedByteArray, handler: HTTPRequest) -> void:
    pass

func _complete(_data = null, _error : BaseError = null) -> void:
    data = _data
    error = _error
    completed.emit(self)
+   unreference()

would you mind making a quick check?

stmn commented 1 year ago

@fenix-hub It works, commited.