Project Setup
DatabaseKit & AuthKit Setup

DatabaseKit & AuthKit Setup

Steps are required for both DatabaseKit and AuthKit to work correctly. If you're only using DatabaseKit, you can skip steps that have are marked with (AuthKit only).

Set up a Google Firebase Project

DatabaseKit is built on top of Google Firebase Firestore. Go to console.firebase.google.com (opens in a new tab) and press on Get Started, followed by Add Project.

Firebase Console Landing Firebase Console Recent Projects

Enter your Project Name and press Continue.

Firebase New Project Name Enter

Disable Google Analytics, as we're using PostHog via AnalyticsKit. Press Create Project.

Firebase New Project Google Analytics Toggle

When your project is created, press Continue.

Firebase Project Created

Set up Firebase Firestore

This is your Project Overview page of Firebase. To create a new Firebase Firestore instance, press on Cloud Firestore.

Firebase Project Overview

On the Cloud Firestore page, press Create Database.

Create Firestore Screen

Select your database location and press Next.

Firestore Creation Location Selection

Select Start in production mode and press Next.

Firestore Creation Security Mode Selection

After the database is created, go to the Rules tab, replace false with true and press on Publish Changes.

Firestore Rules Tab Change Screen

⚠️

This will allow pretty much anyone to write to and read from your database. You can set specific rules to to allow only authenticated users to read and write from your database. For more information, see the Firebase Firestore Security Rules (opens in a new tab).

If you're not using AuthKit, jump straight to Connect Firebase with your App.

Set up Firebase Authentication (AuthKit only)

Go to Project Overview and select Authentication.

Firebase Project Overview

On the Authentication page, press Get Started.

Create Firebase Auth Screen

Enable Email/Password as an Auth Method (AuthKit only)

Enable Email/Password as an authentication method, by going to Sign-in method and pressing Email/Password.

Firebase Auth Sign In Methods Screen

Here, enable the Email/Password toggle and press Save.

Firebase Auth Enable Email Screen

Enable Sign in With Apple (AuthKit only)

Create a Services ID

Go to the Identifiers (opens in a new tab) of your Apple Developer Account and press on the + Button

Apple Developer Identifiers Section

Select Services IDs and press Continue.

New Identifier Type Selection Section

Enter a Services ID Name, enter an Identifier (com.ORG_NAME.APP_NAME.ServicesID where ORG_NAME is the organization name you've entered during Project Initialization) and press Continue.

Then, press Register.

New Identifier Name Enter Section

Back in the Identifiers section, press on the newly created identifier.

Apple Developer Identifiers Section

Enable Sign in with Apple and press on Configure.

Created Identifier Page

In this Configuration Pop-up:

  1. Select your App in the Primary App ID dropdown.
  2. Enter firebaseapp.com,FIREBASE_PROJECT_ID.firebaseapp.com in the Domains and Subdomains URL field.
  3. Enter https://FIREBASE_PROJECT_ID.firebaseapp.com/__/auth/handler in the Return URLs field.
  4. Press Next and Done.

Replace FIREBASE_PROJECT_ID with your Firebase Project ID. You can find it by going to your Firebase Project Overview > Project Settings > General > Project ID.

Return URL Configuration

Press Continue and Save.

Return URL Configuration

Create a .p8 Auth Key for Sign in with Apple

Go to the Keys Section (opens in a new tab) of your Apple Developer Account and press on the + Button

Apple Developer Keys Section

If you have created added a Key to use with NotifKit beforehand, you don't have to create a new one, just press Edit on the one you've already created.

Enter a Key Name, select Sign in with Apple and press Configure.

Apple Developer Key Creation Screen

Select your App ID and press Save.

Apple Developer Key Primary App ID Selection

Press on Continue, then Register.

Don't delete that key. If you are going to enable Push Notifications later, we will use the same key. You can't redownload it, so you'll have to generate a new one.

Apple Developer Key Creation Screen Apple Developer Register Key Screen

Next:

  1. Download the .p8 Key
  2. Write down your Developer Team ID
  3. Write down your Key ID

Apple Developer Download Key

Configure Apple's Private Email Relay Service

We are going to need this to send emails to our users.

Go to the Services Section (opens in a new tab) of your Apple Developer Account and press on the Configure button on the Sign in with Apple for Email Communication Card.

Apple Developer Services Section

Press on the Plus Button next to Email Sources.

Apple Developer Email Sources List Section

Enter noreply@FIREBASE_PROJECT_ID.firebaseapp.com in the Email addresses field. Press Next and Done.

Apple Developer New Email Email Config

If everything is set up correcty, a green checkmark under the Status column will appear.

Apple Developer New Email Source Complete

Connect Sign in with Apple to Firebase (AuthKit only)

Enable Sign in with Apple as an authentication method, by going to Sign-in method and pressing Add Provider and then selecitng Apple.

Firebase Auth Select New Sign In Provider Provider Firebase Auth New Sign In Provider Apple

In the Configuration screen:

  1. Enable the Apple toggle.
  2. Enter your App Bundle ID.
  3. Enter your Team ID.
  4. Enter your Key ID.
  5. Enter the Contents of the .p8 Auth Key you've downloaded. (You can open it with a text editor, like TextEdit).
  6. Press Save.

Firebase Auth Apple Provider Configuration

Don't delete that key. If you are going to enable Push Notifications later, we will use the same key. You can't redownload it, so you'll have to generate a new one.

Connect Firebase with your App

Download the Firebase Configuration File

In the Firebase Project Overview, press on the iOS icon.

Firebase Overview Add iOS

Here, enter your App's Bundle ID, a Firebase App Nickname and press Register App.

Firebase Connect iOS App, Basic Data

Download the GoogleService-Info Property List and skip the rest of the steps.

Firebase Connect iOS App, Download Info Property List

Add the Firebase Configuration File to your App in Xcode

Delete the Placeholder GoogleService-Info.plist file in your Xcode project under Targets > FirebaseKit > Config > GoogleService-Info.plist.

Drag the downloaded GoogleService-Info.plist file into the same location.

Xcode, old GoogleService File

Select YOUR_APP_NAME as a Target and press Finish.

Xcode, Target Select on new GoogleService File

The newly added GoogleService-Info.plist file should appear in your Xcode project.

Xcode, new GoogleService File added

Test if everything is set up correctly

It's recommended to wait until you have set up the rest of your app before doing any tests, but if you can't wait, you can temporarily disable other frameworks.

Run your app on a real device or a simulator. You should be on the first tab, named DB Example. Here, press on the New Post Button in the top right corner. A Sign-In Sheet should appear. Press Continue wiht Apple.

App DBKit Test 1

After a successful log-in, enter a Post Title and press the Publish Button. Now you can see your post in a "Timeline"

App DBKit Test 2

If you go to your Firebase Console, you should see a new user in the Authentication tab and a new post in the Cloud Firestore tab.

App DBKit Test 3

App DBKit Test 4