BackendKit Setup
Perform this setup if after you're done setting up DatabaseKit and AuthKit.
Add Firebase Functions to your Firebase Project
BackendKit is utilizes Firebase Function to built a seamless, scaleble backend for your app. Go to console.firebase.google.com (opens in a new tab) and select Functions in the Sidebar. Press on "Updgrade Project". Set up a payment provider and press on continue (You will only have to setup the billing once, all future Firebase projects can use this billing account). Set the budget amount to $5 to prevent any unexpected costs and press on Continue.
You have to upgrade to the Blaze "Pay-as-you-go" plan to use Firebase Functions. In most apps these costs will not even exceed one dollar and you can always place a monthly budget cap to prevent any unexpected costs.
Install Firebase CLI and initialize Project
Open your terminal and enter the following command to install the Firebase CLI:
Install Node.js first if you haven't already. You can download it from nodejs.org (opens in a new tab).
npm install -g firebase-tools
This is going to take some time.
After installing it, in your terminal, go to the project directory generated by SwiftyLaunch, there /Backend/firebasefunc like this:
cd /path/to/your/GENERATED_APP/Backend/firebasefunc
Open this folder with Visual Studio Code or any other code editor of your choice.
Example with Visual Studio Code:
code .
If the above command doesn't, work, you can open the folder manually by opening Visual Studio Code and selecting the folder.
Here, go to .firebaserc
and enter your Firebase project ID in the default
field. You can find your project ID in the Firebase Console Project Settings.
Back in the terminal, first, (go into the functions folder and) install all the dependencies by running:
cd functions && npm install
Then, if you're deploying for the first time, login to your Firebase account by running:
firebase login
This will open a browser window where you can login to your Firebase account. Press on allow access.
After you have logged in, deploy the Backend Functions to Firebase by running:
firebase deploy --only functions
This will deploy the functions to Firebase. Be sure to always deploy the functions from the functions
folder.
A successful deployment will look like this:
And in the Firebase Console, you should see the functions deployed:
Connect RevenueCat (InAppPurchaseKit)
Go to the Dashboard of your Project in RevenueCat. In the Sidebar, select API Keys and press on New
Then enter a name and Select API Version v1 and press on Generate
Copy the key and add it in the Firebase Functions folder in functions/config.ts
under rcApiKey
.
Connect OneSignal (NotifKit)
After connecting the OneSignal App in the NotifKit Application Setup, go to the OneSignal Dashboard and select the App you just created.
In the Sidebar, select Settings and then Keys & IDs. Here you can find the App ID and REST API Key.
Copy them and add them in the Firebase Functions folder in functions/config.ts
under osAppApiKey
and osAppID
.
Connect PostHog (AnalyticsKit)
Use the same API keys as in the AnalyticsKit Application Setup. Both App and Backend events will appear in the PostHog
dashboard with distinct endpoint_source
properties: app
and backend
.
Add them in config.ts
under postHogAPIKey
and postHogHost
.
Connect OpenAI (AIKit)
Go to the API Keys Section on OpenAI's Platform (opens in a new tab) and click on Create new secret key.
Choose an appropriate name, make sure that it has ALL permissions and press on Create secret key.
Copy the newly produced key and paste it in config.ts
in backend source code under openAIApiKey
.
Test Backend
If everything is setup correctly and you have completely set up all the other frameworks, you can now test the backend by opening the List Users view in the DatabaseExampleView
Here you can see all the different backend functions depending on your selected frameworks
Test Backend (AIKit)
If everything is set up correctly, you can now test the AIKit integration by opening the AIKit Chatty Example by selecting it in the AIKitExamplesView
.