GodotNuts / GodotFirebase

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

[BUG] Firebase.Auth.auth.idtoken is empty #414

Closed TrevorBlythe closed 2 weeks ago

TrevorBlythe commented 2 weeks ago

Im attempting to read and write to a real time database. I have authentication done with some other thing, other then Firebase. I tried to use this function

Firebase.Database.get_database_reference("https://s************.firebaseio.com/")

But got an error

Invalid get index 'idtoken' (on base: 'Dictionary').
database/reference.gd ~ line 124 at function _get_remaining _path

To Reproduce Ubuntu, Godot 4.2.2, Install firebase and run the above line of code.

Expected behavior Should return database reference.

Environment: Ubuntu

WolfgangSenff commented 2 weeks ago

You have to be logged in at the moment - also, that's definitely not the path you want for the reference. It seems like you didn't read the wiki for any of the setup, nor how to use the RealtimeDatabase. Go ahead and check that out here to ensure you're authenticated, https://github.com/GodotNuts/GodotFirebase/wiki/Authentication-and-User-Management, and then here to see how to use the RTDB: https://github.com/GodotNuts/GodotFirebase/wiki/Realtime-Database#connecting. I'm going to go ahead and close this, since I'm certain these two things will fix all your issues.

TrevorBlythe commented 2 weeks ago

But I want the users to authenticate with facebook at runtime, but the only way to authenticate with this is with .env file

TrevorBlythe commented 2 weeks ago

I did anonymous login before the database thing and it still didnt work even with a fixed path same error

TrevorBlythe commented 2 weeks ago

I also left everything empty in the .env file except the database path since I was only using a database and firebase didnt give any api key for it or antyhing

WolfgangSenff commented 2 weeks ago

You have to put the API key. It won't work without that.

TrevorBlythe commented 2 weeks ago

You have to put the API key. It won't work without that.

Realtime database doesn't have an api key

WolfgangSenff commented 2 weeks ago

Stop wasting my time please. 🫤 You have to put all the info they gave you in your file into the .env. The API key is for all of Firebase, not the rtdb.

TrevorBlythe commented 2 weeks ago

Screenshot from 2024-07-10 15-29-24

edit: Also sorry for wasting your time

There is no api key anywhere in the project, I have nothing to host so im cant use firebase hosting, i think that has an api key but im only using rtdb.

WolfgangSenff commented 2 weeks ago

Go into the project settings for your project and add the values you find in this section (note I had to click config at the top, although you don't have to technically) into the .env file. image

TrevorBlythe commented 2 weeks ago

I created a webapp and it gave me the values you were talking about, all the way up to "appID" (no measurementId). It shows the same error though, do I have to create it as an android app instead of a web app?

WolfgangSenff commented 2 weeks ago

No, you shouldn't. You put the apiKey in the right place, and so on, right? And you formatted them the way it is in the sample .env file, right?

TrevorBlythe commented 2 weeks ago

I did I copied from the example env and then pasted my keys in.

Its probably not working because im using the project from the "assetLib" section of Godot instead of the recommended installation. But that is the only one I could use because when I copied over the files from the github instead of downloading it from the assetLib, it says it cannot parse the class.

I looked in the scripts and some of the tool scripts just have the word "tool" at the top of the script, instead of the "@tool" and when I fix those it ends up on an error, "Cannot find PoolStringArray in scope"

Is this addon meant to be ran on 4.2.2?

WolfgangSenff commented 2 weeks ago

Yes, but if you downloaded it that way (from Github), then you accidentally downloaded the 3.x version, called Main. Remember, the plugin has to work on both 3.x and 4.x, and if you see tool with no at symbol, that's the wrong version for 4.x. It should work fine from the asset lib. How about I make a video to show how to set the whole thing up tomorrow, starting a series of videos on the plugin that I've been meaning to make for a while? I'll post a link here directly, as well as all over the place. :P

WolfgangSenff commented 2 weeks ago

If you want to get it from Github directly, you have to go here to get it: https://github.com/GodotNuts/GodotFirebase/tree/4.x. Also, due to a bug in Godot, after you get it and delete your previous version and add the above version into your codebase, make sure (while Godot is completely closed) that you delete your .godot folder in your entire project's folder. It will cause a lot of problems otherwise due to Godot's caching mechanism.

TrevorBlythe commented 2 weeks ago

A video tutorial series on the plugin sounds like a fantastic idea! I've been watching old videos on it but they haven't really got me anywhere except here. I'm really just trying to use this so I can put multiplayer with the real time database. I'll be sure to check the link you post if you decide to do it.

WolfgangSenff commented 2 weeks ago

With multiplayer there, do you mean like actually moving characters around in "realtime" and stuff, or just turn-based? If the former, you unfortunately cannot do that with the realtime database. Aside from the cost (sending tons of updates will cost you a lot of money), it's just not anywhere near fast enough. They call it the realtime database, but that's deceptive - it is not very fast relative to actual multiplayer, like for instance the high-level multiplayer networking API. You really need a dedicated server for it.

TrevorBlythe commented 2 weeks ago

Wow that is kind of deceptive... :(. I did want real time multiplayer but I guess that was never going to work anyway. I wish they gave you a ballpark of how real-time it really was before letting you use it.

WolfgangSenff commented 2 weeks ago

Yeah. Honestly the name has always bothered me as it's deceptive. I'm sorry about that. I'm still working on the video, hopefully can get it out by the weekend.