FIRUser


@interface FIRUser : NSObject <FIRUserInfo>

Represents a user. This class is thread-safe.

  • Indicates the user represents an anonymous user.

    Declaration

    Swift

    var isAnonymous: Bool { get }

    Objective-C

    @property (readonly, getter=isAnonymous, nonatomic) BOOL anonymous;
  • Indicates the email address associated with this user has been verified.

    Declaration

    Swift

    var isEmailVerified: Bool { get }

    Objective-C

    @property (readonly, getter=isEmailVerified, nonatomic) BOOL emailVerified;
  • A refresh token; useful for obtaining new access tokens independently. This property should only be used for advanced scenarios, and is not typically needed.

    Declaration

    Swift

    var refreshToken: String? { get }

    Objective-C

    @property (readonly, nonatomic, nullable) NSString *refreshToken;
  • Profile data for each identity provider, if any. This data is cached on sign-in and updated when linking or unlinking.

    Declaration

    Swift

    var providerData: [UserInfo] { get }

    Objective-C

    @property (readonly, nonatomic, nonnull) NSArray<id<FIRUserInfo>> *providerData;
  • Metadata associated with the Firebase user in question.

    Declaration

    Swift

    var metadata: FIRUserMetadata { get }

    Objective-C

    @property (readonly, nonatomic, nonnull) FIRUserMetadata *metadata;
  • This class should not be instantiated. To retrieve the current user, use FIRAuth.currentUser. To sign a user in or out, use the methods on FIRAuth.

    Declaration

    Objective-C

    - (nonnull instancetype)init;
  • Updates the email address for the user. On success, the cached user profile data is updated. May fail if there is already an account with this email address that was created using email and password authentication.

    Possible error codes:

    • FIRAuthErrorCodeInvalidRecipientEmail - Indicates an invalid recipient email was sent in the request.

    • FIRAuthErrorCodeInvalidSender - Indicates an invalid sender email is set in the console for this action.

    • FIRAuthErrorCodeInvalidMessagePayload - Indicates an invalid email template for sending update email.

    • FIRAuthErrorCodeEmailAlreadyInUse - Indicates the email is already in use by another account.

    • FIRAuthErrorCodeInvalidEmail - Indicates the email address is malformed.

    • FIRAuthErrorCodeRequiresRecentLogin - Updating a user’s email is a security sensitive operation that requires a recent login from the user. This error indicates the user has not signed in recently enough. To resolve, reauthenticate the user by invoking reauthenticateWithCredential:completion: on FIRUser.

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

    Declaration

    Swift

    func updateEmail(to email: String, completion: UserProfileChangeCallback? = nil)

    Objective-C

    - (void)updateEmail:(nonnull NSString *)email
             completion:(nullable FIRUserProfileChangeCallback)completion;

    Parameters

    email

    The email address for the user.

    completion

    Optionally; the block invoked when the user profile change has finished. Invoked asynchronously on the main thread in the future.

  • Updates the password for the user. On success, the cached user profile data is updated.

    Possible error codes:

    • FIRAuthErrorCodeOperationNotAllowed - Indicates the administrator disabled sign in with the specified identity provider.

    • FIRAuthErrorCodeRequiresRecentLogin - Updating a user’s password is a security sensitive operation that requires a recent login from the user. This error indicates the user has not signed in recently enough. To resolve, reauthenticate the user by invoking reauthenticateWithCredential:completion: on FIRUser.

    • FIRAuthErrorCodeWeakPassword - Indicates an attempt to set a password that is considered too weak. The NSLocalizedFailureReasonErrorKey field in the NSError.userInfo dictionary object will contain more detailed explanation that can be shown to the user.

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

    Declaration

    Swift

    func updatePassword(to password: String, completion: UserProfileChangeCallback? = nil)

    Objective-C

    - (void)updatePassword:(nonnull NSString *)password
                completion:(nullable FIRUserProfileChangeCallback)completion;

    Parameters

    password

    The new password for the user.

    completion

    Optionally; the block invoked when the user profile change has finished. Invoked asynchronously on the main thread in the future.

  • Creates an object which may be used to change the user’s profile data.

    Set the properties of the returned object, then call FIRUserProfileChangeRequest.commitChangesWithCallback: to perform the updates atomically.

    Declaration

    Swift

    func createProfileChangeRequest() -> UserProfileChangeRequest

    Objective-C

    - (nonnull FIRUserProfileChangeRequest *)profileChangeRequest;

    Return Value

    An object which may be used to change the user’s profile data atomically.

  • Reloads the user’s profile data from the server.

    May fail with a FIRAuthErrorCodeRequiresRecentLogin error code. In this case you should call FIRUser.reauthenticateWithCredential:completion: before re-invoking FIRUser.updateEmail:completion:.

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

    Declaration

    Swift

    func reload(completion: UserProfileChangeCallback? = nil)

    Objective-C

    - (void)reloadWithCompletion:(nullable FIRUserProfileChangeCallback)completion;

    Parameters

    completion

    Optionally; the block invoked when the reload has finished. Invoked asynchronously on the main thread in the future.

  • Convenience method for reauthenticateAndRetrieveDataWithCredential:completion: This method doesn’t return additional identity provider data.

    Declaration

    Swift

    func reauthenticate(with credential: FIRAuthCredential, completion: UserProfileChangeCallback? = nil)

    Objective-C

    - (void)reauthenticateWithCredential:(nonnull FIRAuthCredential *)credential
                              completion:
                                  (nullable FIRUserProfileChangeCallback)completion;
  • Renews the user’s authentication tokens by validating a fresh set of credentials supplied by the user and returns additional identity provider data.

    If the user associated with the supplied credential is different from the current user, or if the validation of the supplied credentials fails; an error is returned and the current user remains signed in.

    Possible error codes:

    • FIRAuthErrorCodeInvalidCredential - Indicates the supplied credential is invalid. This could happen if it has expired or it is malformed.

    • FIRAuthErrorCodeOperationNotAllowed - Indicates that accounts with the identity provider represented by the credential are not enabled. Enable them in the Auth section of the Firebase console.

    • FIRAuthErrorCodeEmailAlreadyInUse - Indicates the email asserted by the credential (e.g. the email in a Facebook access token) is already in use by an existing account, that cannot be authenticated with this method. Call fetchProvidersForEmail for this user’s email and then prompt them to sign in with any of the sign-in providers returned. This error will only be thrown if the One account per email address setting is enabled in the Firebase console, under Auth settings. Please note that the error code raised in this specific situation may not be the same on Web and Android.

    • FIRAuthErrorCodeUserDisabled - Indicates the user’s account is disabled.

    • FIRAuthErrorCodeWrongPassword - Indicates the user attempted reauthentication with an incorrect password, if credential is of the type EmailPasswordAuthCredential.

    • FIRAuthErrorCodeUserMismatch - Indicates that an attempt was made to reauthenticate with a user which is not the current user.

    • 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 reauthenticateAndRetrieveData(with credential: FIRAuthCredential, completion: AuthDataResultCallback? = nil)

    Objective-C

    - (void)
    reauthenticateAndRetrieveDataWithCredential:
        (nonnull FIRAuthCredential *)credential
                                     completion:(nullable FIRAuthDataResultCallback)
                                                    completion;

    Parameters

    credential

    A user-supplied credential, which will be validated by the server. This can be a successful third-party identity provider sign-in, or an email address and password.

    completion

    Optionally; the block invoked when the re-authentication operation has finished. Invoked asynchronously on the main thread in the future.

  • Retrieves the Firebase authentication token, possibly refreshing it if it has expired.

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

    Declaration

    Swift

    func getIDToken(completion: AuthTokenCallback? = nil)

    Objective-C

    - (void)getIDTokenWithCompletion:(nullable FIRAuthTokenCallback)completion;

    Parameters

    completion

    Optionally; the block invoked when the token is available. Invoked asynchronously on the main thread in the future.

  • Please use getIDTokenWithCompletion: instead.

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

    Declaration

    Swift

    func getToken(completion: AuthTokenCallback? = nil)

    Objective-C

    - (void)getTokenWithCompletion:(nullable FIRAuthTokenCallback)completion;

    Parameters

    completion

    Optionally; the block invoked when the token is available. Invoked asynchronously on the main thread in the future.

  • Retrieves the Firebase authentication token, possibly refreshing it if it has expired.

    The authentication token will be refreshed (by making a network request) if it has expired, or if forceRefresh is YES.

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

    Declaration

    Swift

    func getIDTokenForcingRefresh(_ forceRefresh: Bool, completion: AuthTokenCallback? = nil)

    Objective-C

    - (void)getIDTokenForcingRefresh:(BOOL)forceRefresh
                          completion:(nullable FIRAuthTokenCallback)completion;

    Parameters

    forceRefresh

    Forces a token refresh. Useful if the token becomes invalid for some reason other than an expiration.

    completion

    Optionally; the block invoked when the token is available. Invoked asynchronously on the main thread in the future.

  • Please use getIDTokenForcingRefresh:completion instead.

    The authentication token will be refreshed (by making a network request) if it has expired, or if forceRefresh is YES.

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

    Declaration

    Swift

    func getTokenForcingRefresh(_ forceRefresh: Bool, completion: AuthTokenCallback? = nil)

    Objective-C

    - (void)getTokenForcingRefresh:(BOOL)forceRefresh
                        completion:(nullable FIRAuthTokenCallback)completion;

    Parameters

    forceRefresh

    Forces a token refresh. Useful if the token becomes invalid for some reason other than an expiration.

    completion

    Optionally; the block invoked when the token is available. Invoked asynchronously on the main thread in the future.

  • Convenience method for linkAndRetrieveDataWithCredential:completion: This method doesn’t return additional identity provider data.

    Declaration

    Swift

    func link(with credential: FIRAuthCredential, completion: AuthResultCallback? = nil)

    Objective-C

    - (void)linkWithCredential:(nonnull FIRAuthCredential *)credential
                    completion:(nullable FIRAuthResultCallback)completion;
  • Associates a user account from a third-party identity provider with this user and returns additional identity provider data.

    Possible error codes:

    • FIRAuthErrorCodeProviderAlreadyLinked - Indicates an attempt to link a provider of a type already linked to this account.

    • FIRAuthErrorCodeCredentialAlreadyInUse - Indicates an attempt to link with a credential that has already been linked with a different Firebase account.

    • FIRAuthErrorCodeOperationNotAllowed - Indicates that accounts with the identity provider represented by the credential are not enabled. Enable them in the Auth section of the Firebase console.

    This method may also return error codes associated with updateEmail:completion: and updatePassword:completion: on FIRUser.

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

    Declaration

    Swift

    func linkAndRetrieveData(with credential: FIRAuthCredential, completion: AuthDataResultCallback? = nil)

    Objective-C

    - (void)
    linkAndRetrieveDataWithCredential:(nonnull FIRAuthCredential *)credential
                           completion:
                               (nullable FIRAuthDataResultCallback)completion;

    Parameters

    credential

    The credential for the identity provider.

    completion

    Optionally; the block invoked when the unlinking is complete, or fails. Invoked asynchronously on the main thread in the future.

  • Disassociates a user account from a third-party identity provider with this user.

    Possible error codes:

    • FIRAuthErrorCodeNoSuchProvider - Indicates an attempt to unlink a provider that is not linked to the account.

    • FIRAuthErrorCodeRequiresRecentLogin - Updating email is a security sensitive operation that requires a recent login from the user. This error indicates the user has not signed in recently enough. To resolve, reauthenticate the user by invoking reauthenticateWithCredential:completion: on FIRUser.

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

    Declaration

    Swift

    func unlink(fromProvider provider: String, completion: AuthResultCallback? = nil)

    Objective-C

    - (void)unlinkFromProvider:(nonnull NSString *)provider
                    completion:(nullable FIRAuthResultCallback)completion;

    Parameters

    provider

    The provider ID of the provider to unlink.

    completion

    Optionally; the block invoked when the unlinking is complete, or fails. Invoked asynchronously on the main thread in the future.

  • Initiates email verification for the user.

    Possible error codes:

    • FIRAuthErrorCodeInvalidRecipientEmail - Indicates an invalid recipient email was sent in the request.

    • FIRAuthErrorCodeInvalidSender - Indicates an invalid sender email is set in the console for this action.

    • FIRAuthErrorCodeInvalidMessagePayload - Indicates an invalid email template for sending update email.

    • FIRAuthErrorCodeUserNotFound - Indicates the user account was not found.

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

    Declaration

    Swift

    func sendEmailVerification(completion: SendEmailVerificationCallback? = nil)

    Objective-C

    - (void)sendEmailVerificationWithCompletion:
        (nullable FIRSendEmailVerificationCallback)completion;

    Parameters

    completion

    Optionally; the block invoked when the request to send an email verification is complete, or fails. Invoked asynchronously on the main thread in the future.

  • Initiates email verification for the user.

    Possible error codes:

    • FIRAuthErrorCodeInvalidRecipientEmail - Indicates an invalid recipient email was sent in the request.

    • FIRAuthErrorCodeInvalidSender - Indicates an invalid sender email is set in the console for this action.

    • FIRAuthErrorCodeInvalidMessagePayload - Indicates an invalid email template for sending update email.

    • FIRAuthErrorCodeUserNotFound - Indicates the user account was not found.

    • FIRAuthErrorCodeMissingIosBundleID - Indicates that the iOS bundle ID is missing when a iOS App Store ID is provided.

    • FIRAuthErrorCodeMissingAndroidPackageName - Indicates that the android package name is missing when the androidInstallApp flag is set to true.

    • FIRAuthErrorCodeUnauthorizedDomain - Indicates that the domain specified in the continue URL is not whitelisted in the Firebase console.

    • FIRAuthErrorCodeInvalidContinueURI - Indicates that the domain specified in the continue URI is not valid.

    Declaration

    Swift

    func sendEmailVerification(with actionCodeSettings: FIRActionCodeSettings, completion: SendEmailVerificationCallback? = nil)

    Objective-C

    - (void)
    sendEmailVerificationWithActionCodeSettings:
        (nonnull FIRActionCodeSettings *)actionCodeSettings
                                     completion:
                                         (nullable FIRSendEmailVerificationCallback)
                                             completion;

    Parameters

    actionCodeSettings

    An FIRActionCodeSettings object containing settings related to handling action codes.

  • Deletes the user account (also signs out the user, if this was the current user).

    Possible error codes:

    • FIRAuthErrorCodeRequiresRecentLogin - Updating email is a security sensitive operation that requires a recent login from the user. This error indicates the user has not signed in recently enough. To resolve, reauthenticate the user by invoking reauthenticateWithCredential:completion: on FIRUser.

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

    Declaration

    Swift

    func delete(completion: UserProfileChangeCallback? = nil)

    Objective-C

    - (void)deleteWithCompletion:(nullable FIRUserProfileChangeCallback)completion;

    Parameters

    completion

    Optionally; the block invoked when the request to delete the account is complete, or fails. Invoked asynchronously on the main thread in the future.