Developer-facing classes included in the firebase_app_lite
folder.
The core of the Godot Firebase Lite API. The parent node to all Firebase apps and services.
Construct this as an "AutoLoad Singleton" and not as a regular class. (Although, you can instantiate it as a new class instead if you really would rather manage it that way.)
Create a firebase
global namespace (AutoLoad Singleton) by going into Project Settings > AutoLoad tab, and add a new entry with the following settings:
- Path:
res://firebase_app_lite/firebase.gd
(or wherever you put it) - Name:
firebase
(note this is all lower case -- if you try proper case it will generate a conflict error with theFirebase
class [Godot's style guide is mixed up about class instances]) - Singleton: [x] Enable
Then, for example, to initialize the default app to work with a database service:
# Set the configuration options for your app.
# TODO: Replace with your project's config object.
var firebase_config = {
"apiKey": "", # set somewhere only if using auth
"authDomain": "your-awesome-app.firebaseapp.com",
"databaseURL": "https://your-awesome-app-db.region-maybe.firebaseio.com",
"projectId": "your-awesome-app",
"storageBucket": "your-awesome-app.appspot.com",
"messagingSenderId": "111111111111",
"appId": "1:111111111111:web:aaaaaaaaaaaaaaaaaaaaaa"
}
# Initialize Firebase
firebase.initialize_app(firebase_config)
# Get a reference to the database service.
var db : FirebaseDatabase = firebase.database()
Constant | Type | Description |
---|---|---|
SDK_VERSION |
String |
The current SDK version. |
Method | Returns (cast as) | Typical usage |
---|---|---|
app(<name>) |
FirebaseApp |
Retrieves a Firebase app instance. |
auth(<app>) |
Node (FirebaseAuth ) |
Gets the FirebaseAuth service for the default app or a given app. |
database(<app>) |
Node (FirebaseDatabase ) |
Gets the FirebaseDatabase service for the default app or a given app. |
initialize_app(options, <name>) |
FirebaseApp |
Creates and initializes a Firebase app instance. |
Note: If <name>
or <app>
is not specified with any of the above methods, the default app is assumed. These parameters allow for more apps to be managed that just the one default app.
See Add Firebase to your app and Initialize multiple projects for detailed documentation.
Differences from the JavaScript SDK:
apps
array property replaced by GDScript's child Node handling such asget_children()
andget_node(name)
.- Cases changed from camelCase to snake_case, where appropriate. For example,
initializeApp()
renamed toinitialize_app()
. (Well, the key names in the Firebase app config were not changed because... uh... to make copying from Firebase's console easier... I suppose. Hrmm. No standards here [or in Godot] with dictionary key names.) app()
,auth()
, anddatabase()
are module calls in JS but are methods here. (What's the difference? Nothing that matters in lite.)- This lite version does not implement all features.
A Firebase app holds the initialization information for a collection of services.
Do not call this constructor directly. Instead, use firebase.initialize_app()
to create an app.
Property | Type | Description |
---|---|---|
name |
String |
The name for this app. The default app's name is "[DEFAULT]". |
options |
Dictionary |
The (read-only) configuration options for this app. |
Method | Returns (cast as) | Typical usage |
---|---|---|
auth() |
Node (FirebaseAuth ) |
Loads and gets the FirebaseAuth service for the current app. |
database() |
Node (FirebaseDatabase ) |
Loads and gets the FirebaseDatabase service for the current app. |
delete() |
void | TODO. Renders this app unusable and frees the resources of all associated services. |
Differences from the JavaScript SDK:
name
property is actually provided by theNode
class rather than this class. As such, it is not read only -- and perhaps does not need to be given the new architecture in theFirebase
class. You should not, however, rename the default app.- This lite version does not implement all features.
A Firebase error.
Created to overcome nuances in GDScript. There is, however, a similar class in Firebase (see the source docs below).
var result = yield(ref.update({"name": "Pelé"}), "completed")
if result is FirebaseError:
print(result.code)
else:
# do something
Property | Type | Description |
---|---|---|
code |
String |
Error codes are strings using the following format: "service/string-code" . Some examples include "app/no-app" and "auth/user-not-found" . |