Get Started with Firebase Authentication on Apple Platforms
Stay organized with collectionsSave and categorize content based on your preferences.
You can useFirebase Authenticationto allow users to sign in to your app using one or
more sign-in methods, including email address and password sign-in, and
federated identity providers such as Google Sign-in and Facebook Login. This
tutorial gets you started withFirebase Authenticationby showing you how to add
email address and password sign-in to your app.
In theFirebaseconsole, add your app to your Firebase project.
AddFirebase Authenticationto your app
Use Swift Package Manager to install and manage Firebase dependencies.
In Xcode, with your app project open, navigate toFile > Add Packages.
When prompted, add the Firebase Apple platforms SDK repository:
https://github.com/firebase/firebase-ios-sdk.git
Choose theFirebase Authenticationlibrary.
Add the-ObjCflag to theOther Linker Flagssection of your target's build settings.
When finished, Xcode will automatically begin resolving and downloading your
dependencies in the background.
(Optional) Prototype and test withFirebase Local Emulator Suite
Before talking about how your app authenticates users, let's introduce a set of
tools you can use to prototype and testAuthenticationfunctionality:Firebase Local Emulator Suite. If you're deciding among authentication techniques
and providers, trying out different data models with public and private data
usingAuthenticationandFirebase Security Rules, or prototyping sign-in UI designs, being able to
work locally without deploying live services can be a great idea.
AnAuthenticationemulator is part of theLocal Emulator Suite, which
enables your app to interact with emulated database content and config, as
well as optionally your emulated project resources (functions, other databases,
and security rules).
Using theAuthenticationemulator 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, runningfirebase emulators:start.
Using theLocal Emulator SuiteUI for interactive prototyping, or theAuthenticationemulator REST API for non-interactive testing.
For each of your app's views that need information about the signed-in user,
attach a listener to theFIRAuthobject. This listener gets called whenever
the user's sign-in state changes.
Attach the listener in the view controller'sviewWillAppearmethod:
Create a form that allows new users to register with your app using their email
address and a password. When a user completes the form, validate the email
address and password provided by the user, then pass them to thecreateUsermethod:
After a user signs in successfully, you can get information about the user. For
example, 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+=" "}// ...}
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;// ...}
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Missing the information I need","missingTheInformationINeed","thumb-down"],["Too complicated / too many steps","tooComplicatedTooManySteps","thumb-down"],["Out of date","outOfDate","thumb-down"],["Samples / code issue","samplesCodeIssue","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2025-09-04 UTC."],[],[],null,["You can use Firebase Authentication to allow users to sign in to your app using one or\nmore sign-in methods, including email address and password sign-in, and\nfederated identity providers such as Google Sign-in and Facebook Login. This\ntutorial gets you started with Firebase Authentication by showing you how to add\nemail address and password sign-in to your app.\n\nConnect your app to Firebase \n\n1. [Install the Firebase SDK](/docs/ios/setup).\n2. In the [Firebase console](//console.firebase.google.com/), add your app to your Firebase project.\n\nAdd Firebase Authentication to your app\n\nUse Swift Package Manager to install and manage Firebase dependencies.\n| Visit [our installation guide](/docs/ios/installation-methods) to learn about the different ways you can add Firebase SDKs to your Apple project, including importing frameworks directly and using CocoaPods.\n\n1. In Xcode, with your app project open, navigate to **File \\\u003e Add Packages**.\n2. When prompted, add the Firebase Apple platforms SDK repository: \n\n```text\n https://github.com/firebase/firebase-ios-sdk.git\n```\n| **Note:** New projects should use the default (latest) SDK version, but you can choose an older version if needed.\n3. Choose the Firebase Authentication library.\n4. Add the `-ObjC` flag to the *Other Linker Flags* section of your target's build settings.\n5. When finished, Xcode will automatically begin resolving and downloading your dependencies in the background.\n\n| **Important:** For Mac apps, enable the Keychain Sharing capability so the SDK has permission to store user entries in the keychain. For more information, see the [FAQ guide](/docs/ios/troubleshooting-faq#macos-keychain-sharing).\n\n(Optional) Prototype and test with Firebase Local Emulator Suite\n\nBefore talking about how your app authenticates users, let's introduce a set of\ntools you can use to prototype and test Authentication functionality:\nFirebase Local Emulator Suite. If you're deciding among authentication techniques\nand providers, trying out different data models with public and private data\nusing Authentication and Firebase Security Rules, or prototyping sign-in UI designs, being able to\nwork locally without deploying live services can be a great idea.\n\nAn Authentication emulator is part of the Local Emulator Suite, which\nenables your app to interact with emulated database content and config, as\nwell as optionally your emulated project resources (functions, other databases,\nand security rules).\n\nUsing the Authentication emulator involves just a few steps:\n\n1. Adding a line of code to your app's test config to connect to the emulator.\n2. From the root of your local project directory, running `firebase emulators:start`.\n3. Using the Local Emulator Suite UI for interactive prototyping, or the Authentication emulator REST API for non-interactive testing.\n\nA detailed guide is available at [Connect your app to the Authentication emulator](/docs/emulator-suite/connect_auth).\nFor more information, see the [Local Emulator Suite introduction](/docs/emulator-suite).\n\nNow let's continue with how to authenticate users.\n\nInitialize the Firebase SDK\n\nIn your app delegate, first import the Firebase SDK: \n\nSwift \n\n import FirebaseCore \n https://github.com/firebase/quickstart-ios/blob/6e483be884a13ffe8d6258f1a626662fa9e7d837/authentication/LegacyAuthQuickstart/AuthenticationExampleSwift/AppDelegate.swift#L20-L20\n\nObjective-C \n\n @import FirebaseCore; \n https://github.com/firebase/quickstart-ios/blob/6e483be884a13ffe8d6258f1a626662fa9e7d837/authentication/LegacyAuthQuickstart/AuthenticationExample/AppDelegate.m#L21-L21\n\nThen, in the `application:didFinishLaunchingWithOptions:` method, initialize the\n`FirebaseApp` object: \n\nSwift \n\n // Use Firebase library to configure APIs\n FirebaseApp.configure() \n https://github.com/firebase/quickstart-ios/blob/6e483be884a13ffe8d6258f1a626662fa9e7d837/authentication/LegacyAuthQuickstart/AuthenticationExampleSwift/AppDelegate.swift#L40-L41\n\nObjective-C \n\n // Use Firebase library to configure APIs\n [FIRApp configure]; \n https://github.com/firebase/quickstart-ios/blob/6e483be884a13ffe8d6258f1a626662fa9e7d837/authentication/LegacyAuthQuickstart/AuthenticationExample/AppDelegate.m#L34-L35\n\nListen for authentication state\n\nFor each of your app's views that need information about the signed-in user,\nattach a listener to the `FIRAuth` object. This listener gets called whenever\nthe user's sign-in state changes.\n\nAttach the listener in the view controller's `viewWillAppear` method: \n\nSwift \n\n handle = Auth.auth().addStateDidChangeListener { auth, user in\n // ...\n } \n https://github.com/firebase/quickstart-ios/blob/6e483be884a13ffe8d6258f1a626662fa9e7d837/authentication/LegacyAuthQuickstart/AuthenticationExampleSwift/MainViewController.swift#L505-L510\n\nObjective-C \n\n self.handle = [[FIRAuth auth]\n addAuthStateDidChangeListener:^(FIRAuth *_Nonnull auth, FIRUser *_Nullable user) {\n // ...\n }]; \n https://github.com/firebase/quickstart-ios/blob/6e483be884a13ffe8d6258f1a626662fa9e7d837/authentication/LegacyAuthQuickstart/AuthenticationExample/MainViewController.m#L575-L581\n\nAnd detach the listener in the view controller's `viewWillDisappear` method: \n\nSwift \n\n Auth.auth().removeStateDidChangeListener(handle!) \n https://github.com/firebase/quickstart-ios/blob/6e483be884a13ffe8d6258f1a626662fa9e7d837/authentication/LegacyAuthQuickstart/AuthenticationExampleSwift/MainViewController.swift#L523-L523\n\nObjective-C \n\n [[FIRAuth auth] removeAuthStateDidChangeListener:_handle]; \n https://github.com/firebase/quickstart-ios/blob/6e483be884a13ffe8d6258f1a626662fa9e7d837/authentication/LegacyAuthQuickstart/AuthenticationExample/MainViewController.m#L604-L604\n\nSign up new users\n\nCreate a form that allows new users to register with your app using their email\naddress and a password. When a user completes the form, validate the email\naddress and password provided by the user, then pass them to the `createUser`\nmethod: \n\nSwift \n\n Auth.auth().createUser(withEmail: email, password: password) { authResult, error in\n // ...\n } \n https://github.com/firebase/quickstart-ios/blob/6e483be884a13ffe8d6258f1a626662fa9e7d837/authentication/LegacyAuthQuickstart/AuthenticationExampleSwift/EmailViewController.swift#L173-L184\n\nObjective-C \n\n [[FIRAuth auth] createUserWithEmail:email\n password:password\n completion:^(FIRAuthDataResult * _Nullable authResult,\n NSError * _Nullable error) {\n // ...\n }]; \n https://github.com/firebase/quickstart-ios/blob/6e483be884a13ffe8d6258f1a626662fa9e7d837/authentication/LegacyAuthQuickstart/AuthenticationExample/EmailViewController.m#L170-L184\n\nSign in existing users\n\nCreate a form that allows existing users to sign in using their email address\nand password. When a user completes the form, call the `signIn` method: \n\nSwift \n\n Auth.auth().signIn(withEmail: email, password: password) { [weak self] authResult, error in\n guard let strongSelf = self else { return }\n // ...\n } \n https://github.com/firebase/quickstart-ios/blob/6e483be884a13ffe8d6258f1a626662fa9e7d837/authentication/LegacyAuthQuickstart/AuthenticationExampleSwift/EmailViewController.swift#L37-L99\n\nObjective-C \n\n [[FIRAuth auth] signInWithEmail:self-\u003e_emailField.text\n password:self-\u003e_passwordField.text\n completion:^(FIRAuthDataResult * _Nullable authResult,\n NSError * _Nullable error) {\n // ...\n }]; \n https://github.com/firebase/quickstart-ios/blob/6e483be884a13ffe8d6258f1a626662fa9e7d837/authentication/LegacyAuthQuickstart/AuthenticationExample/EmailViewController.m#L36-L89\n\nGet user information\n\nAfter a user signs in successfully, you can get information about the user. For\nexample, in your [authentication state listener](#listen_for_authentication_state): \n\nSwift \n\n if let user = user {\n // The user's ID, unique to the Firebase project.\n // Do NOT use this value to authenticate with your backend server,\n // if you have one. Use getTokenWithCompletion:completion: instead.\n let uid = user.uid\n let email = user.email\n let photoURL = user.photoURL\n var multiFactorString = \"MultiFactor: \"\n for info in user.multiFactor.enrolledFactors {\n multiFactorString += info.displayName ?? \"[DispayName]\"\n multiFactorString += \" \"\n }\n // ...\n } \n https://github.com/firebase/quickstart-ios/blob/6e483be884a13ffe8d6258f1a626662fa9e7d837/authentication/LegacyAuthQuickstart/AuthenticationExampleSwift/MainViewController.swift#L590-L636\n\nObjective-C \n\n if (user) {\n // The user's ID, unique to the Firebase project.\n // Do NOT use this value to authenticate with your backend server,\n // if you have one. Use getTokenWithCompletion:completion: instead.\n NSString *email = user.email;\n NSString *uid = user.uid;\n NSMutableString *multiFactorString = [NSMutableString stringWithFormat:@\"MultiFactor: \"];\n for (FIRMultiFactorInfo *info in user.multiFactor.enrolledFactors) {\n [multiFactorString appendString:info.displayName];\n [multiFactorString appendString:@\" \"];\n }\n NSURL *photoURL = user.photoURL;\n // ...\n } \n https://github.com/firebase/quickstart-ios/blob/6e483be884a13ffe8d6258f1a626662fa9e7d837/authentication/LegacyAuthQuickstart/AuthenticationExample/MainViewController.m#L647-L688\n\nNext steps\n\nLearn how to add support for other identity providers and anonymous guest\naccounts:\n\n- [Google Sign-in](/docs/auth/ios/google-signin)\n- [Facebook Login](/docs/auth/ios/facebook-login)\n- [Twitter Login](/docs/auth/ios/twitter-login)\n- [GitHub Login](/docs/auth/ios/github-auth)\n- [Anonymous sign-in](/docs/auth/ios/anonymous-auth)"]]