How to add Firebase Authentication to SwiftUI
What Firebase Authentication does for an iOS app
Authentication is the part of an app most teams do not want to build from scratch: password hashing, token refresh, email verification, password reset, and social providers. Firebase Authentication handles all of it. You get a stable user ID per account, session tokens that refresh on their own, and providers you can turn on from the Firebase console. It pairs naturally with Firestore, where Security Rules can reference the signed-in user to decide what each account can read or write.
Adding Firebase Authentication with AppFlight
In AppFlight you open the integrations panel, choose Firebase, and connect your project. AppFlight adds the Firebase Swift package, places your GoogleService-Info.plist in the app, and calls FirebaseApp.configure() at launch. The plist is a client file, so it is safe in the binary, and AppFlight never tries to embed an Admin SDK credential, which belongs only on a backend. From there you can ask the AI to add a sign-in screen, an auth state listener, or Sign in with Apple, and it generates the SwiftUI for you.
A SwiftUI example
Configure Firebase at launch, then sign a user in with email and password:
import SwiftUI
import FirebaseCore
import FirebaseAuth
@main
struct MyApp: App {
init() { FirebaseApp.configure() }
var body: some Scene {
WindowGroup { SignInView() }
}
}
struct SignInView: View {
@State private var email = ""
@State private var password = ""
@State private var error: String?
var body: some View {
VStack(spacing: 12) {
TextField("Email", text: $email)
.textInputAutocapitalization(.never)
SecureField("Password", text: $password)
Button("Sign in") {
Task { await signIn() }
}
if let error {
Text(error).foregroundStyle(.red)
}
}
.padding()
}
func signIn() async {
do {
try await Auth.auth().signIn(withEmail: email, password: password)
} catch {
self.error = error.localizedDescription
}
}
}
To create an account instead, call Auth.auth().createUser(withEmail:password:). To react to login state across the app, attach Auth.auth().addStateDidChangeListener and update a view model.
Alternatives
Supabase Auth covers the same ground with a Postgres backend and row-level security, and AppFlight uses Supabase as its keystone, so it is the default when you want SQL. Sign in with Apple alone is the lightest option if you only need one provider and no email or password storage. Firebase Authentication is the strongest pick when you want several providers, managed sessions, and a quick path to Firestore with rules tied to the user.
FAQ
Does Firebase Authentication need a secret key in the app?
No. Firebase ships a GoogleService-Info.plist that holds identifiers, not a secret. Access is controlled by Firebase Security Rules and Auth state on the server, not by hiding the config. The Admin SDK service account is the secret credential and it stays on a backend only.
Can I use Firebase Auth with Sign in with Apple?
Yes. Firebase supports Apple as a provider, and if your app offers any third-party login, Apple requires you to also offer Sign in with Apple under the App Store guidelines. Firebase exchanges the Apple credential for a Firebase session.
Where does the user session live?
Firebase persists the session in the keychain and refreshes the token automatically. You read Auth.auth().currentUser or attach an auth state listener to drive your SwiftUI views. No password is stored in your own database.