Skip to content

Conversation

stmn
Copy link

@stmn stmn commented Dec 29, 2022

  1. Restored error type.

Reason:

  • it is useful
  • it is used in demos & examples (it will be simpler to convert them to Godot 4)
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:

  • assigning null to dictionary type causing error
  • logout is totally not working (no body in response)
  1. Added missing awaits

Reason:

  • sign in is just not working for GDScript style, I'm using todo demo (adjusted for 4.x) like below:
# 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(
		"[email protected]",
		"userpwd"
	)

func _on_signed_in(user: SupabaseUser) -> void:
	print(user)

@stmn
Copy link
Author

stmn commented Dec 29, 2022

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

This was made due to error "Resumed function 'push_request()' after await, but class instance is gone"
@fenix-hub
Copy link
Collaborator

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
Copy link
Author

stmn commented Dec 29, 2022

@fenix-hub It works, commited.

@fenix-hub fenix-hub merged commit f3269d8 into supabase-community:4.x Dec 30, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants