GodotNuts / GodotFirebase

Implementations of Firebase for Godot using GDScript
MIT License
517 stars 74 forks source link

login succeeded bug #413

Closed isthargames closed 1 week ago

isthargames commented 2 weeks ago

Hello everyone

I recently updated to the latest version of the plugin in my project, and I've noticed some changes in the code. Currently, I'm experiencing a bug that didn't occur in the previous version.

It consists in that when I log in with an email and the _on_loginsucceeded(auth) function verifies it as correct, it makes me redirect infinitely to a scene, which is clearly inefficient and frustrating. Since when it verifies the file it does: _get_tree().call_deferred("change_scene_to_packed", ResourceLoader.load_threaded_get(LoadScenes.homescene)). Before it worked very well, because once I logged in it would redirect me to the home scene only once, now I don't know why it does it infinitely. Or I could delete all the code from the function and leave a print("logged in correctly") to see what happens, but it still prints infinitely. What can I do to fix this?

Here's my code:


func _ready() -> void:

    Firebase.Auth.login_succeeded.connect(on_login_succeeded)
    Firebase.Auth.login_failed.connect(on_login_failed)

    Firebase.Auth.signup_succeeded.connect(on_signup_succeeded)
    Firebase.Auth.signup_failed.connect(on_signup_failed)

    Firebase.Auth.connect("userdata_received", Callable(self, "_on_userdata_received"))

    check_auth()

func check_auth():

    if Firebase.Auth.check_auth_file():
        login_profile.visible = true
        logout_profile.visible = false
    else:
        login_profile.visible = false
        logout_profile.visible = true

func on_login_succeeded(auth):

    print(auth)
    Firebase.Auth.save_auth(auth)
    SoundManager.play_sound_save()
    get_tree().call_deferred("change_scene_to_packed", ResourceLoader.load_threaded_get(LoadScenes.home_scene))

func _on_my_profile_pressed():
    SoundManager.play_sound_select()
    background.visible = true
    if Firebase.Auth.check_auth_file():
        my_profile_window.visible = true
    else:
        no_login_window.visible = true
isthargames commented 2 weeks ago

https://github.com/GodotNuts/GodotFirebase/assets/149918776/e33df3a5-32b5-48e4-9fe1-63a6124564dc

WolfgangSenff commented 2 weeks ago

Hm. It doesn't do that anywhere for anyone else, so I'm inclined to believe this is a bug in your code. I'm guessing it only worked before because you weren't saving the auth file or something correctly. https://github.com/GodotNuts/GodotFirebase/blob/fa306a52e2c84980912955dd00b91abe36027723/addons/godot-firebase/auth/auth.gd#L510 this function attempts to log you in automatically, so it looks like something in your code is causing it to go infinite. I recommend you use needs_login() instead of check_auth_file(). You can find that function here: https://github.com/GodotNuts/GodotFirebase/blob/fa306a52e2c84980912955dd00b91abe36027723/addons/godot-firebase/auth/auth.gd#L387

isthargames commented 2 weeks ago

Umm it's a little strange because I've reviewed a lot and using need_login() it still does the same thing, the only solution I could do is:

func check_auth():
    if Firebase.Auth.check_auth_file():
        Firebase.Auth.login_succeeded.disconnect(on_login_succeeded)
        login_profile.visible = true
        logout_profile.visible = false
    else:
        login_profile.visible = false
        logout_profile.visible = true
WolfgangSenff commented 2 weeks ago

Best I can do at this point is have you private message me on Discord with a zip of your project so I can fix it. I can't see enough of your code to know what's wrong otherwise, since all my projects and the test harness work fine.

WolfgangSenff commented 1 week ago

Closing after no response for two weeks.