Auth

class Auth : NSObject

Manages authentication for Firebase apps. This class is thread-safe.

  • Gets the auth object for the default Firebase app. The default Firebase app must have already been configured or an exception will be raised.

    Declaration

    Swift

    class func auth() -> Auth
  • Gets the auth object for a FIRApp.

    Declaration

    Swift

    class func auth(app: FIRApp) -> Auth

    Parameters

    app

    The FIRApp for which to retrieve the associated FIRAuth instance.

    Return Value

    The FIRAuth instance associated with the given FIRApp.

  • app

    Gets the FIRApp object that this auth object is connected to.

    Declaration

    Swift

    weak var app: FIRApp? { get }
  • Synchronously gets the cached current user, or null if there is none.

    Declaration

    Swift

    var currentUser: FIRUser? { get }
  • The current user language code. This property can be set to the app’s current language by calling useAppLanguage.

    The string used to set this property must be a language code that follows BCP 47.

    Declaration

    Swift

    var languageCode: String? { get set }
  • Contains settings related to the auth object.

    Declaration

    Swift

    @NSCopying var settings: FIRAuthSettings? { get set }
  • The current user access group that the Auth instance is using. Default is nil.

    Declaration

    Swift

    var userAccessGroup: String? { get }
  • The APNs token used for phone number authentication. The type of the token (production or sandbox) will be attempted to be automatcially detected. If swizzling is disabled, the APNs Token must be set for phone number auth to work, by either setting this property or by calling setAPNSToken:type:

    Declaration

    Swift

    var apnsToken: Data? { get set }
  • Please access auth instances using FIRAuth.auth and FIRAuth.authForApp:.

  • Sets the currentUser on the calling Auth instance to the provided user object.

    Declaration

    Swift

    func updateCurrentUser(_ user: FIRUser, completion: UserUpdateCallback? = nil)

    Parameters

    user

    The user object to be set as the current user of the calling Auth instance.

    completion

    Optionally; a block invoked after the user of the calling Auth instance has been updated or an error was encountered.

  • Please use fetchSignInMethodsForEmail:completion: for Objective-C or fetchSignInMethods(forEmail:completion:) for Swift instead.

    Declaration

    Swift

    func fetchProviders(forEmail email: String, completion: ProviderQueryCallback? = nil)
  • Fetches the list of all sign-in methods previously used for the provided email address.

    Possible error codes:

    + `FIRAuthErrorCodeInvalidEmail` - Indicates the email address is malformed.
    

    See FIRAuthErrors for a list of error codes that are common to all API methods.

    Declaration

    Swift

    func fetchSignInMethods(forEmail email: String, completion: SignInMethodQueryCallback? = nil)

    Parameters

    email

    The email address for which to obtain a list of sign-in methods.

    completion

    Optionally; a block which is invoked when the list of sign in methods for the specified email address is ready or an error was encountered. Invoked asynchronously on the main thread in the future.

  • Signs in using an email address and password.

    Possible error codes:

    + `FIRAuthErrorCodeOperationNotAllowed` - Indicates that email and password
        accounts are not enabled. Enable them in the Auth section of the
        Firebase console.
    + `FIRAuthErrorCodeUserDisabled` - Indicates the user's account is disabled.
    + `FIRAuthErrorCodeWrongPassword` - Indicates the user attempted
        sign in with an incorrect password.
    + `FIRAuthErrorCodeInvalidEmail` - Indicates the email address is malformed.
    

    See FIRAuthErrors for a list of error codes that are common to all API methods.

    Declaration

    Swift

    func signIn(withEmail email: String, password: String, completion: AuthDataResultCallback? = nil)

    Parameters

    email

    The user’s email address.

    password

    The user’s password.

    completion

    Optionally; a block which is invoked when the sign in flow finishes, or is canceled. Invoked asynchronously on the main thread in the future.

  • Signs in using an email address and email sign-in link.

    Possible error codes:

    + `FIRAuthErrorCodeOperationNotAllowed` - Indicates that email and email sign-in link
        accounts are not enabled. Enable them in the Auth section of the
        Firebase console.
    + `FIRAuthErrorCodeUserDisabled` - Indicates the user's account is disabled.
    + `FIRAuthErrorCodeInvalidEmail` - Indicates the email address is invalid.
    

    See FIRAuthErrors for a list of error codes that are common to all API methods.

    Declaration

    Swift

    func signIn(withEmail email: String, link: String, completion: AuthDataResultCallback? = nil)

    Parameters

    email

    The user’s email address.

    link

    The email sign-in link.

    completion

    Optionally; a block which is invoked when the sign in flow finishes, or is canceled. Invoked asynchronously on the main thread in the future.

  • Signs in using the provided auth provider instance.

    Possible error codes:

    • FIRAuthErrorCodeOperationNotAllowed - Indicates that email and password accounts are not enabled. Enable them in the Auth section of the Firebase console.
    • FIRAuthErrorCodeUserDisabled - Indicates the user’s account is