Get Started with Firebase Authentication on Apple Platforms Stay organized with collections Save and categorize content based on your preferences.
You can useFirebase Authentication to allow users to sign in to your app using one ormore sign-in methods, including email address and password sign-in, andfederated identity providers such as Google Sign-in and Facebook Login. Thistutorial gets you started withFirebase Authentication by showing you how to addemail address and password sign-in to your app.
Connect your app to Firebase
- Install the Firebase SDK.
- In theFirebase console, add your app to your Firebase project.
AddFirebase Authentication to your app
Use Swift Package Manager to install and manage Firebase dependencies.
Visitour installation guide to learn about the different ways you can add Firebase SDKs to your Apple project.- In Xcode, with your app project open, navigate toFile > Add Packages.
- When prompted, add the Firebase Apple platforms SDK repository:
- Choose theFirebase Authentication library.
- Add the
-ObjCflag to theOther Linker Flags section of your target's build settings. - When finished, Xcode will automatically begin resolving and downloading your dependencies in the background.
https://github.com/firebase/firebase-ios-sdk.git
(Optional) Prototype and test withFirebase Local Emulator Suite
Before talking about how your app authenticates users, let's introduce a set oftools you can use to prototype and testAuthentication functionality:Firebase Local Emulator Suite. If you're deciding among authentication techniquesand providers, trying out different data models with public and private datausingAuthentication andFirebase Security Rules, or prototyping sign-in UI designs, being able towork locally without deploying live services can be a great idea.
AnAuthentication emulator is part of theLocal Emulator Suite, whichenables your app to interact with emulated database content and config, aswell as optionally your emulated project resources (functions, other databases,and security rules).
Using theAuthentication emulator involves just a few steps:
- Adding a line of code to your app's test config to connect to the emulator.
- From the root of your local project directory, running
firebase emulators:start. - Using theLocal Emulator Suite UI for interactive prototyping, or theAuthentication emulator REST API for non-interactive testing.
A detailed guide is available atConnect your app to theAuthentication emulator.For more information, see theLocal Emulator Suite introduction.
Now let's continue with how to authenticate users.
Initialize the Firebase SDK
In your app delegate, first import the Firebase SDK:
Swift
importFirebaseCoreObjective-C
@importFirebaseCore;Then, in theapplication:didFinishLaunchingWithOptions: method, initialize theFirebaseApp object:
Swift
// Use Firebase library to configure APIsFirebaseApp.configure()Objective-C
// Use Firebase library to configure APIs[FIRAppconfigure];Listen for authentication state
For each of your app's views that need information about the signed-in user,attach a listener to theFIRAuth object. This listener gets called wheneverthe user's sign-in state changes.
Attach the listener in the view controller'sviewWillAppear method:
Swift
handle=Auth.auth().addStateDidChangeListener{auth,userin// ...}Objective-C
self.handle=[[FIRAuthauth]addAuthStateDidChangeListener:^(FIRAuth*_Nonnullauth,FIRUser*_Nullableuser){// ...}];And detach the listener in the view controller'sviewWillDisappear method:
Swift
Auth.auth().removeStateDidChangeListener(handle!)Objective-C
[[FIRAuthauth]removeAuthStateDidChangeListener:_handle];Sign up new users
Create a form that allows new users to register with your app using their emailaddress and a password. When a user completes the form, validate the emailaddress and password provided by the user, then pass them to thecreateUsermethod:
Swift
Auth.auth().createUser(withEmail:email,password:password){authResult,errorin// ...}Objective-C
[[FIRAuthauth]createUserWithEmail:emailpassword:passwordcompletion:^(FIRAuthDataResult*_NullableauthResult,NSError*_Nullableerror){// ...}];Sign in existing users
Create a form that allows existing users to sign in using their email addressand password. When a user completes the form, call thesignIn method:
Swift
Auth.auth().signIn(withEmail:email,password:password){[weakself]authResult,erroringuardletstrongSelf=selfelse{return}// ...}Objective-C
[[FIRAuthauth]signInWithEmail:self->_emailField.textpassword:self->_passwordField.textcompletion:^(FIRAuthDataResult*_NullableauthResult,NSError*_Nullableerror){// ...}];Get user information
After a user signs in successfully, you can get information about the user. Forexample, in yourauthentication state listener:
Swift
ifletuser=user{// The user's ID, unique to the Firebase project.// Do NOT use this value to authenticate with your backend server,// if you have one. Use getTokenWithCompletion:completion: instead.letuid=user.uidletemail=user.emailletphotoURL=user.photoURLvarmultiFactorString="MultiFactor: "forinfoinuser.multiFactor.enrolledFactors{multiFactorString+=info.displayName??"[DispayName]"multiFactorString+=" "}// ...}Objective-C
if(user){// The user's ID, unique to the Firebase project.// Do NOT use this value to authenticate with your backend server,// if you have one. Use getTokenWithCompletion:completion: instead.NSString*email=user.email;NSString*uid=user.uid;NSMutableString*multiFactorString=[NSMutableStringstringWithFormat:@"MultiFactor: "];for(FIRMultiFactorInfo*infoinuser.multiFactor.enrolledFactors){[multiFactorStringappendString:info.displayName];[multiFactorStringappendString:@" "];}NSURL*photoURL=user.photoURL;// ...}Next steps
Learn how to add support for other identity providers and anonymous guestaccounts:
Except as otherwise noted, the content of this page is licensed under theCreative Commons Attribution 4.0 License, and code samples are licensed under theApache 2.0 License. For details, see theGoogle Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.
Last updated 2026-02-18 UTC.