Firebase

Getting Started

Setting up Firebase in your SwiftStruct project.


Create a Firebase project

  1. Go to the Firebase Console
  2. Sign in with your Google account
  3. Click "Add project" or "Create a project"
  4. Enter your project name
  5. Choose whether to enable Google Analytics (optional)
  6. Click "Create project" and wait for it to finish

Set up Firebase products

Authentication

  1. In the Firebase Console, go to Authentication in the left sidebar
  2. Click "Get started"
  3. Enable the sign-in methods you want to use:
    • Email/Password: Enable and save
    • Sign in with Apple: Enable and configure
    • Google: Enable and configure
    • GitHub: Enable and configure. To create a GitHub OAuth app:
      1. Go to GitHub Settings → Developer settings → OAuth Apps
      2. Click "New OAuth App"
      3. Enter an application name
      4. Set the Authorization callback URL to: https://YOUR_PROJECT_ID.firebaseapp.com/__/auth/handler
      5. Click "Register application"
      6. Copy the Client ID and Client secret
      7. Paste them into Firebase Authentication settings
    • Phone: Enable and configure

Firestore Database

  1. Go to Firestore Database in the left sidebar
  2. Click "Create database"
  3. Choose to start in production mode or test mode (the project comes with sensible defaults)
  4. Select a location for your database (choose the closest to your users)
  5. Click "Enable"

Storage

  1. Go to Storage in the left sidebar
  2. Click "Get started"
  3. Review the security rules (the project comes with sensible defaults)
  4. Choose a storage location
  5. Click "Done"

Hosting

Important for passwordless email authentication

This step is required if you plan to use email link sign-in (passwordless email authentication). The email links will not work without Firebase Hosting enabled.

  1. Go to Hosting in the left sidebar
  2. Click "Get started"

Add an iOS app

  1. In your Firebase project, click the iOS icon to add an iOS app
  2. Enter your iOS bundle ID (use what you used during setup, found in your Xcode project settings)
  3. Register the app
  4. Download the GoogleService-Info.plist file
  5. Add the GoogleService-Info.plist file to Resources/GoogleService-Info.plist in your Xcode project

Configure associated domains

Required for email link authentication

This configuration is necessary for Universal Links to work properly, which are used by Firebase email link authentication and Dynamic Links.

  1. Open your Xcode project
  2. Select your app target in the project navigator
  3. Go to the Signing & Capabilities tab
  4. Find the Associated Domains capability
  5. Replace the existing domain with your Firebase project ID: applinks:your-project-id.firebaseapp.com

Configure URL Types

Required for authentication

These URL schemes allow your app to receive authentication callbacks from Google Sign-In and other Firebase services.

  1. In your Xcode project, select your app target
  2. Go to the Info tab
  3. Expand the URL Types section
  4. Open your GoogleService-Info.plist file to get the required values
  5. Update both URL Types:
    • First URL Type (googleusercontent): Replace the URL Scheme with your REVERSED_CLIENT_ID value (should look like com.googleusercontent.apps.XXXXXX)
    • Second URL Type (bundle ID): Replace the URL Scheme with your BUNDLE_ID value (your app's bundle identifier)

Deploy Firebase configuration

Required for all functionality

This deployment step is essential for your app to work properly. It deploys security rules for Firestore and Storage, configures all authentication methods, and sets up the necessary backend infrastructure. Without completing this step, sign-in methods, database access, and storage operations will not function correctly.

  1. Navigate to apps/firebase in your project
  2. Run firebase login if you haven't already authenticated
  3. Open .firebaserc and replace the project ID with your Firebase project ID:
    {
      "projects": {
        "default": "your-project-id"
      }
    }
    
  4. Open firebase.json and verify the configuration matches your database setup (regions, storage buckets, etc.)
  5. Run firebase deploy to deploy all rules and configuration
  6. Accept all prompts during the deployment process

Note: Functions may fail on the first deployment. If this happens, simply run firebase deploy again.

Previous
Architecture guide