GodotNuts / GodotFirebase

Implementations of Firebase for Godot using GDScript
MIT License
532 stars 76 forks source link

[BUG] Firestore not being able to fetch/add data #288

Closed iRedFox closed 2 years ago

iRedFox commented 2 years ago

Describe the bug Firestore doesn't allow me to fetch/add data even though the collection does exist. I've drawn a flow chart for how does my program work (I can provide source-code if needed, contact me through discord RedFox#0001 (ping me in official GodotFirebase discord)

console:

ERROR: HTTPRequest is processing a request. Wait for completion or cancel it before attempting a new one.
   at: (scene/main/http_request.cpp:82)
[Firebase] >> Unauthenticated request issued...
[Firebase Error] >> Firebase Auth is currently busy and cannot process this request
[Firebase] >> Client authenticated as Anonymous User.
action: 0
[Firebase Error] >> Unknown error when returning from task

To Reproduce Sign-in and authenticate through google sign-in, once logged signal have been emitted. var document_task : FirestoreTask = usersCollection.get(login.email) get document task and check if user exists or not. If not then add user to firestore database.

Expected behavior Here's two functions (one for once user is found and one when user does not exists)

# If user exists then this function will run
func _on_user_found(document: FirestoreDocument, login_dict) -> void:
    if (document.doc_fields.country == ""):
        # show country selector if he has no country selected yet
        $Countries.show()
    else:
        $Menu/CenterRow/Buttons/Scoreboard.show()
        $Menu/CenterRow/Buttons/Play.show()

# If user does not exists, then we will add it to the database
func _on_user_get_error(code, status, message, login_dict) -> void:
    print("I'm registering the user")
    var add_task : FirestoreTask = usersCollection.add(login_dict.email, {'username': login_dict.firstname, 'points': 0, 'country': "", 'skins': []})
    var addDocument : FirestoreTask = yield(add_task, "task_finished")
    $Countries.show()
    $Menu/GoogleSignContainer.hide()
    $Background/Username.hide()

Screenshots Flow chart: img

Environment:

Additional context Its not authentication issue. Its Firestore database not being able to do a task I've tried doing this debug messages and nothing showed up.

#firestore_task.gd line:175 DEBUGGING
else:
    print(action)    
    print("bod: ", bod)
    emit_signal("task_error", 1, 0, "Unknown error when returning from task")

output:

0
bod: {}
[Firebase Error] >> Unknown error when returning from task
iRedFox commented 2 years ago

The issue was because my User schema is different than code schema. var add_task : FirestoreTask = usersCollection.add(login_dict.email, {'username': login_dict.firstname, 'points': 0, 'country': "", 'skins': []})

Is different than the one in Firestore.