Firebase
Getting Started
Setting up Firebase in your SwiftStruct project.
Create a Firebase project
- Go to the Firebase Console
- Sign in with your Google account
- Click "Add project" or "Create a project"
- Enter your project name
- Choose whether to enable Google Analytics (optional)
- Click "Create project" and wait for it to finish
Set up Firebase products
Authentication
- In the Firebase Console, go to Authentication in the left sidebar
- Click "Get started"
- 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:
- Go to GitHub Settings → Developer settings → OAuth Apps
- Click "New OAuth App"
- Enter an application name
- Set the Authorization callback URL to:
https://YOUR_PROJECT_ID.firebaseapp.com/__/auth/handler - Click "Register application"
- Copy the Client ID and Client secret
- Paste them into Firebase Authentication settings
- Phone: Enable and configure
Firestore Database
- Go to Firestore Database in the left sidebar
- Click "Create database"
- Choose to start in production mode or test mode (the project comes with sensible defaults)
- Select a location for your database (choose the closest to your users)
- Click "Enable"
Storage
- Go to Storage in the left sidebar
- Click "Get started"
- Review the security rules (the project comes with sensible defaults)
- Choose a storage location
- 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.
- Go to Hosting in the left sidebar
- Click "Get started"
Add an iOS app
- In your Firebase project, click the iOS icon to add an iOS app
- Enter your iOS bundle ID (use what you used during setup, found in your Xcode project settings)
- Register the app
- Download the
GoogleService-Info.plistfile - Add the
GoogleService-Info.plistfile toResources/GoogleService-Info.plistin 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.
- Open your Xcode project
- Select your app target in the project navigator
- Go to the Signing & Capabilities tab
- Find the Associated Domains capability
- 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.
- In your Xcode project, select your app target
- Go to the Info tab
- Expand the URL Types section
- Open your
GoogleService-Info.plistfile to get the required values - Update both URL Types:
- First URL Type (googleusercontent): Replace the URL Scheme with your
REVERSED_CLIENT_IDvalue (should look likecom.googleusercontent.apps.XXXXXX) - Second URL Type (bundle ID): Replace the URL Scheme with your
BUNDLE_IDvalue (your app's bundle identifier)
- First URL Type (googleusercontent): Replace the URL Scheme with your
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.
- Navigate to
apps/firebasein your project - Run
firebase loginif you haven't already authenticated - Open
.firebasercand replace the project ID with your Firebase project ID:{ "projects": { "default": "your-project-id" } } - Open
firebase.jsonand verify the configuration matches your database setup (regions, storage buckets, etc.) - Run
firebase deployto deploy all rules and configuration - Accept all prompts during the deployment process
Note: Functions may fail on the first deployment. If this happens, simply run firebase deploy again.