How to Implement Firebase Authentication in iOS: Complete Guide

Implement user authentication in an iOS app with Firebase by configuring the Firebase Console, installing FirebaseAuth via Swift Package Manager, and calling Firebase APIs for sign up, login, and user management.

Setting Up Firebase in Firebase Console

Go to the Firebase Console and sign in with your Google account. Create a new project. Click the iOS icon to add an iOS app. Enter your app's bundle identifier exactly as it appears in Xcode.

Click Register App. Download the GoogleService-Info.plist file. Drag this file into your Xcode project root directory with Copy items if needed checked.

Installing FirebaseAuth with Swift Package Manager

In Xcode 26, go to File and select Add Package Dependencies. Enter the Firebase iOS SDK repository URL:

https://github.com/firebase/firebase-ios-sdk

Select FirebaseAuth from the package list. Xcode downloads and integrates the package.

Initializing Firebase in the App

Open AppDelegate.swift. Import Firebase and call FirebaseApp.configure in the didFinishLaunchingWithOptions method:

import Firebase

class AppDelegate: UIResponder, UIApplicationDelegate {
    func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
        FirebaseApp.configure()
        return true
    }
}

FirebaseApp.configure reads GoogleService-Info.plist and configures all Firebase services for your project.

Enabling Email and Password Authentication

In the Firebase Console, select Authentication from the side menu. Click Sign-in Method. Find the Email and Password provider. Enable the toggle and click Save.

Implementing User Sign Up

Use Auth.auth().createUser to register new accounts:

@IBAction func signUpTapped(_ sender: UIButton) {
    guard let email = emailTextField.text, !email.isEmpty,
          let password = passwordTextField.text, !password.isEmpty,
          let name = nameTextField.text, !name.isEmpty else {
        showAlert("Sign Up Error", "Please fill in all fields.")
        return
    }

    Auth.auth().createUser(withEmail: email, password: password) { result, error in
        if let error = error {
            self.showAlert("Registration Error", error.localizedDescription)
            return
        }

        let changeRequest = Auth.auth().currentUser?.createProfileChangeRequest()
        changeRequest?.displayName = name
        changeRequest?.commitChanges()

        self.navigateToMainView()
    }
}

The createUser method creates the account and signs the user in automatically. Use createProfileChangeRequest to set the display name on the Firebase user object.

Implementing User Login

Use Auth.auth().signIn to authenticate existing users:

@IBAction func loginTapped(_ sender: UIButton) {
    guard let email = emailTextField.text, !email.isEmpty,
          let password = passwordTextField.text, !password.isEmpty else {
        showAlert("Login Error", "Both fields must not be blank.")
        return
    }

    Auth.auth().signIn(withEmail: email, password: password) { result, error in
        if let error = error {
            self.showAlert("Login Error", error.localizedDescription)
            return
        }

        self.navigateToMainView()
    }
}

Firebase returns descriptive error messages for invalid credentials, unverified emails, and disabled accounts.

Implementing Logout

Call Auth.auth().signOut to end a user session:

@IBAction func logoutTapped(_ sender: UIButton) {
    do {
        try Auth.auth().signOut()
        navigateToWelcomeScreen()
    } catch {
        showAlert("Logout Error", error.localizedDescription)
    }
}

The signOut method throws an error on failure. After successful logout, present the login screen.

Accessing the Current User Profile

Retrieve the current user's information through Auth.auth().currentUser:

if let user = Auth.auth().currentUser {
    nameLabel.text = user.displayName
    emailLabel.text = user.email
}

The currentUser property persists across app launches. The user stays authenticated until explicitly signed out.

Implementing Password Reset

Send a password reset email with sendPasswordReset:

@IBAction func resetPasswordTapped(_ sender: UIButton) {
    guard let email = emailTextField.text, !email.isEmpty else {
        showAlert("Input Error", "Please provide your email address.")
        return
    }

    Auth.auth().sendPasswordReset(withEmail: email) { error in
        let title = error == nil ? "Success" : "Error"
        let message = error == nil ? "Check your email for a password reset link." : error!.localizedDescription
        self.showAlert(title, message)
    }
}

Firebase handles the email template for password resets. Customize the sender name and email body in the Firebase Console under Authentication and Templates.

Implementing Email Verification

Require verified emails to prevent spam accounts. Call sendEmailVerification after successful sign up:

Auth.auth().currentUser?.sendEmailVerification { error in
    if let error = error {
        print("Verification email failed: (error.localizedDescription)")
    }
}
showAlert("Verify Email", "A verification link has been sent to your email address.")

Blocking Unverified Users

Check isEmailVerified in the login completion handler:

Auth.auth().signIn(withEmail: email, password: password) { result, error in
    guard let result = result, result.user.isEmailVerified else {
        self.promptForVerification()
        return
    }
    self.navigateToMainView()
}

Provide a resend option for users who did not receive the verification email:

private func promptForVerification() {
    let alert = UIAlertController(title: "Email Not Verified", message: "Please verify your email before logging in.", preferredStyle: .alert)
    alert.addAction(UIAlertAction(title: "Resend Email", style: .default) { _ in
        Auth.auth().currentUser?.sendEmailVerification()
    })
    alert.addAction(UIAlertAction(title: "Cancel", style: .cancel))
    present(alert, animated: true)
}

Best Practices for Firebase Authentication

Validate all input fields before making network calls. Check for empty fields and invalid email formats locally. This improves user experience and reduces unnecessary API requests.

Display Firebase error messages in user-friendly alerts. Firebase returns localized error descriptions that are readable. Common errors include The email address is badly formatted, The email address is already in use, and The password must be 6 characters long or more.

Secure GoogleService-Info.plist. Add it to .gitignore. Do not commit it to public repositories.

Summary

This tutorial covered the complete implementation process from setup to working code. You now have a functional implementation that you can extend and customize for your own projects. The same patterns apply to related features in the iOS ecosystem.

Frequently Asked Questions

What Xcode version do I need for this tutorial? This tutorial uses Xcode 26 with Swift 6.2. The code examples work with any recent version of Xcode that supports the frameworks used here.

What are the prerequisites for this tutorial? You need Xcode installed on a Mac and basic familiarity with Swift programming. No prior experience with the specific framework is required.

All articles