-
Notifications
You must be signed in to change notification settings - Fork 84
Buildfire Firebase Integration
This sdk documentation is deprecated and will not be updated. Check out our new docs at https://sdk.buildfire.com/docs/firebase-integration/
buildfire.services.firebase
This is a built in API that allows your control or widget to integrate with Firebase - Google.
This service requires you to include buildfire/services/firebase/firebase.js with your plugin
From the Control
<script src="../../../../scripts/buildfire/services/firebase/firebase.js"></script>
From the Widget
<script src="../../../scripts/buildfire/services/firebase/firebase.js"></script>
Running Example: https://github.com/BuildFire/simpleBuildFireJSExamples/tree/master/exampleFirebaseIntegrationplugin
Before start working with this service, first you need to generate your own integration token from integration page found in BuildFire Developer Portal.
In the integration page you will need to add your private firebase certificate. You can download your certificate from Firebase Console ➡️Project settings ➡️Service Accounts (TAB), then click on GENREATE NEW PRIVATE KEY to download the certificate JSON file. Then you will have to assign whatever plugins you need to allow them to integration to your firebase database, then take the generated integration token to use it in your plugin.
Reminder you still need to include your own firebase sdk
<script src="https://www.gstatic.com/firebasejs/XXX.XXXX.XXX/firebase.js"></script>
If you are using Firebase Auth in both Content & Widget side then you need to set the Authentication state persists:'none'.
Since we are using iframes in Control Panel for both Content & Widget side, we need to make Firebase auth to use the memory instead of local storage/session tabs, to avoid overlapping between the firebase logged user in both CP & Widget, so you might get the wrong logged user in Content or Widget side.
For further details click here.
Used for FireBase custom login. This will integrate on the server-side to create an authenticated custom token on firebase. It will also port over a buildfire user record to your database.
-
options: object-
integrationToken: string -
forceLogin: boolean (optional), will force cached users to login again to firebase
-
-
callback(err, data): callback function after create custom token is completed. Data contains a token property, which is the custom token gererated by firebase. -
Example
buildfire.services.firebase.createCustomToken(
{integrationToken: "Your Integration token"},
function (e, r) {
if(r) console.log(r.token);
}
);
After calling the custom token you will have the buildfire user added to your firebase under buildfire database that you provided in the integration page.
Used to return the root path for collections to use this path where you can build your collections for the current appId.
-
options: object-
scope: string, to get the collection that where you want to save and access data, default value isinstancescope values:-
app: To share data and collections between all plugins and instances. -
plugin: To share data and collections between all instances for the same plugin. -
instance: Every instance has its own data and collections.
-
-
-
callback(err, rootPath): callback function contains the root path for the collections -
Example
buildfire.services.firebase.getRootPath(
{scope: "instance"},
function (e, rootPath) {
//access your data from the root path
}
);
Used to return the collection path for collection name to use this path where you can save data in the specified scope.
-
options: object-
scope: string, to get the collection that where you want to save and access data, default value isinstancescope values:-
app: To share data and collections between all plugins and instances. -
plugin: To share data and collections between all instances for the same plugin. -
instance: Every instance has its own data and collections.
-
-
collectionName: string
-
-
callback(err, collectionPath): callback function contains the collection path for the collection name -
Example
buildfire.services.firebase.getCollectionPath(
{scope: "instance", collectionName: "cities"},
function (e, collectionPath) {
//access your data from the collection path
}
);