Represents a user's profile information in your Firebase project's user database. It also contains helper methods to change or retrieve profile information, as well as to manage that user's authentication state.
Inherited Constant Summary
Public Constructor Summary
Public Method Summary
Task<Void> |
delete()
Deletes the user record from your Firebase project's database.
|
abstract String |
getDisplayName()
Returns the main display name of this user from the Firebase project's user
database.
|
abstract String |
getEmail()
Returns the main email address of the user, as stored in the Firebase project's
user database.
|
Task<GetTokenResult> |
getIdToken(boolean forceRefresh)
Fetches a Firebase Auth ID Token for the user; useful when authenticating
against your own backend.
|
abstract FirebaseUserMetadata |
getMetadata()
Returns the
FirebaseUserMetadata
associated with this user.
|
abstract MultiFactor |
getMultiFactor()
Returns a
MultiFactor
instance which is the main entry point for multi-factor related operations on
this user.
|
abstract String |
getPhoneNumber()
Returns the phone number of the user, as stored in the Firebase project's user
database, or
null if none exists.
|
abstract Uri |
getPhotoUrl()
Returns the URL of this user's main profile picture, as stored in the Firebase
project's user database.
|
abstract List<? extends UserInfo> | |
abstract String |
getProviderId()
Always returns
FirebaseAuthProvider.PROVIDER_ID
|
abstract String |
getTenantId()
Returns the tenant ID of the current user or
null if this user
isn't associated with a tenant project.
|
abstract String |
getUid()
Returns a string used to uniquely identify your user in your Firebase project's
user database.
|
abstract boolean |
isAnonymous()
Returns true if the user is anonymous; that is, the user account was created
with
FirebaseAuth.signInAnonymously() and has not been linked to another
account with
linkWithCredential(AuthCredential) .
|
Task<AuthResult> | |
Task<Void> | |
Task<AuthResult> |
reauthenticateAndRetrieveData(AuthCredential
credential)
Reauthenticates the user with the given credential, and returns the profile
data for that account.
|
Task<Void> |
reload()
Manually refreshes the data of the current user (for example, attached
providers, display name, and so on).
|
Task<Void> |
sendEmailVerification(ActionCodeSettings
actionCodeSettings)
Initiates email verification for the user.
|
Task<Void> |
sendEmailVerification()
Calls
sendEmailVerification(ActionCodeSettings) with null
actionCodeSettings .
|
Task<AuthResult> |
startActivityForLinkWithProvider(Activity
activity, FederatedAuthProvider
federatedAuthProvider)
Links the user using the mobile browser (either a Custom Chrome Tab or the
device's default browser) to the given
provider .
|
Task<AuthResult> |
startActivityForReauthenticateWithProvider(Activity
activity, FederatedAuthProvider
federatedAuthProvider)
Reauthenticates the user using the mobile browser (either a Custom Chrome Tab
or the device's default browser) using the given
provider .
|
Task<AuthResult> | |
Task<Void> | |
Task<Void> | |
Task<Void> | |
Task<Void> | |
Task<Void> |
verifyBeforeUpdateEmail(String newEmail)
Calls
verifyBeforeUpdateEmail(String, ActionCodeSettings) without any
actionCodeSettings .
|
Task<Void> |
verifyBeforeUpdateEmail(String newEmail,
ActionCodeSettings
actionCodeSettings)
Sends a verification email to
newEmail .
|
Inherited Method Summary
Public Constructors
public FirebaseUser ()
Public Methods
public Task<Void> delete ()
Deletes the user record from your Firebase project's database. If the operation is successful, the user will be signed out.
Important: this is a security sensitive operation that requires the user to
have recently signed in. If this requirement isn't met, ask the user to authenticate
again and later call
reauthenticate(AuthCredential)
.
Exceptions
FirebaseAuthInvalidUserException
thrown if the current user's account has been disabled, deleted, or its credentials are no longer validFirebaseAuthRecentLoginRequiredException
thrown if the user's last sign-in time does not meet the security threshold. Usereauthenticate(AuthCredential)
to resolve. This does not apply if the user is anonymous.
public abstract String getDisplayName ()
Returns the main display name of this user from the Firebase project's user
database. Unlike the display name property from instances of UserInfo
corresponding to authentication providers (like Google Sign-In), which is not
modifiable, this name can be updated at any time by calling
updateProfile(UserProfileChangeRequest)
.
This field will be automatically populated on account creation if the AuthCredential
used on
FirebaseAuth.signInWithCredential(AuthCredential)
contained such
information.
public abstract String getEmail ()
Returns the main email address of the user, as stored in the Firebase project's user
database. Unlike the email property from instances of UserInfo
corresponding to authentication providers (like Github), which is not modifiable, this
email address can be updated at any time by calling
updateEmail(String)
.
This field will be automatically populated on account creation if the AuthCredential
used on
FirebaseAuth.signInWithCredential(AuthCredential)
contained such
information, or if the account was created with
FirebaseAuth.createUserWithEmailAndPassword(String, String)
. However, this
is not true if the setting "Multiple Accounts per Email" is enabled in the Firebase
Console - in that case this will be null unless the account was created with
FirebaseAuth.createUserWithEmailAndPassword(String, String)
or
updateEmail(String)
has been called.
If the user also has a password, this email address can be used to sign in into the
account using
FirebaseAuth.signInWithEmailAndPassword(String, String)
.
This email address is displayed in the Users section of the Firebase console.
See Also
public Task<GetTokenResult> getIdToken (boolean forceRefresh)
Fetches a Firebase Auth ID Token for the user; useful when authenticating against your own backend. Use our server SDKs or follow the official documentation to securely verify the integrity and validity of this token.
Exceptions
FirebaseAuthInvalidUserException
ifforceRefresh == true
, thrown if the current user's account has been disabled, deleted, or its credentials are no longer valid
Parameters
forceRefresh | force refreshes the token. Should only be set to true if the token
is invalidated out of band. |
---|
Returns
- a
Task
with theGetTokenResult
public abstract FirebaseUserMetadata getMetadata ()
Returns the FirebaseUserMetadata
associated with this user.
public abstract MultiFactor getMultiFactor ()
Returns a MultiFactor
instance which is the main entry point for multi-factor related operations on this
user.
public abstract String getPhoneNumber ()
Returns the phone number of the user, as stored in the Firebase project's user
database, or null
if none exists. This can be updated at any time by
calling
updatePhoneNumber(PhoneAuthCredential)
.
This field will be automatically populated on account creation if the AuthCredential
used on
FirebaseAuth.signInWithCredential(AuthCredential)
contained such
information. This phone number is displayed in the Users section of the Firebase
console.
public abstract Uri getPhotoUrl ()
Returns the URL of this user's main profile picture, as stored in the Firebase
project's user database. Unlike the profile URL property from instances of
UserInfo
corresponding to authentication providers (like Facebook Login), which is not
modifiable, this URL can be updated at any time by calling
updateProfile(UserProfileChangeRequest)
.
This field will be automatically populated on account creation if the AuthCredential
used on
FirebaseAuth.signInWithCredential(AuthCredential)
contained such
information.
public abstract List<? extends UserInfo> getProviderData ()
Returns a List
of
UserInfo
objects
that represents the linked identities of the user using different authentication
providers that may be linked to their account. Use this to access, for example, your
user's basic profile information retrieved from Facebook whether or not the user used
Facebook Login to sign in to the current session.
public abstract String getProviderId ()
Always returns FirebaseAuthProvider.PROVIDER_ID
public abstract String getTenantId ()
Returns the tenant ID of the current user or null
if this user isn't
associated with a tenant project.
public abstract String getUid ()
Returns a string used to uniquely identify your user in your Firebase project's user database. Use it when storing information in Firebase Database or Storage, or even in your own backend.
This identifier is opaque and does not correspond necessarily to the user's email address or any other field.
public abstract boolean isAnonymous ()
Returns true if the user is anonymous; that is, the user account was created with
FirebaseAuth.signInAnonymously()
and has not been linked to another account with
linkWithCredential(AuthCredential)
.
public Task<AuthResult> linkWithCredential (AuthCredential credential)
Attaches the given AuthCredential
to the user. This allows the user to sign in to this account in the future with
credentials for such provider.
Exceptions
FirebaseAuthWeakPasswordException
thrown ifcredential instanceof EmailAuthCredential
and the password is not strong enoughFirebaseAuthInvalidCredentialsException
thrown if thecredential
is malformed or expiredFirebaseAuthUserCollisionException
thrown if there is another user account associated with the givencredential
FirebaseAuthInvalidUserException
thrown if the current user's account has been disabled, deleted, or its credentials are no longer validFirebaseAuthRecentLoginRequiredException
thrown ifcredential instanceof EmailAuthCredential
and if the user's last sign-in time does not meet the security threshold. Usereauthenticate(AuthCredential)
to resolve. This does not apply if the user is anonymous.FirebaseAuthException
thrown if there is an attempt to link a provider that is already linked to this account or if an internal error occurs
Parameters
credential | a valid credential of a type not yet linked to this user |
---|
Returns
Task
ofAuthResult
public Task<Void> reauthenticate (AuthCredential credential)
Reauthenticates the user with the given credential. This is useful for operations
that require a recent sign-in, to prevent or resolve a
FirebaseAuthRecentLoginRequiredException
.
Exceptions
FirebaseAuthInvalidUserException
thrown if the current user's account has been disabled or deletedFirebaseAuthInvalidCredentialsException
thrown if thecredential
is malformed or has expired, or if it corresponds to another existing user's account. Inspect the error code to desambiguate.
Parameters
credential | authentication credential that must be valid for the current user. |
---|
public Task<AuthResult> reauthenticateAndRetrieveData (AuthCredential credential)
Reauthenticates the user with the given credential, and returns the profile data for
that account. This is useful for operations that require a recent sign-in, to prevent
or resolve a
FirebaseAuthRecentLoginRequiredException
.
Exceptions
FirebaseAuthInvalidUserException
thrown if the current user's account has been disabled or deletedFirebaseAuthInvalidCredentialsException
thrown if thecredential
is malformed or has expired, or if it corresponds to another existing user's account. Inspect the error code to desambiguate.
Parameters
credential | authentication credential that must be valid for the current user. |
---|
Returns
AuthResult
containing theFirebaseUser
reference andAdditionalUserInfo
.
public Task<Void> reload ()
Manually refreshes the data of the current user (for example, attached providers, display name, and so on).
Exceptions
FirebaseAuthInvalidUserException
thrown if the current user's account has been disabled, deleted, or its credentials are no longer valid
public Task<Void> sendEmailVerification (ActionCodeSettings actionCodeSettings)
Initiates email verification for the user. Takes in an ActionCodeSettings
to allow linking back to your app in the email.
Returns
Task
to track completion of the sending operation.
public Task<Void> sendEmailVerification ()
Calls
sendEmailVerification(ActionCodeSettings)
with null
actionCodeSettings
.
public Task<AuthResult> startActivityForLinkWithProvider (Activity activity, FederatedAuthProvider federatedAuthProvider)
Links the user using the mobile browser (either a Custom Chrome Tab or the device's
default browser) to the given provider
. If the calling activity dies
during this operation, use FirebaseAuth.getPendingAuthResult()
to get the outcome of this operation.
Note: this call has a UI associated with it, unlike the majority of calls in FirebaseAuth.
Exceptions
FirebaseAuthInvalidCredentialsException
thrown if the credential generated from the flow is malformed or expired.FirebaseAuthInvalidUserException
thrown if the user has been disabled by an administrator.FirebaseAuthUserCollisionException
thrown if the email that keys the user that is signing in is already in use.FirebaseAuthWebException
thrown if there is an operation already in progress, the pending operation was canceled, there is a problem with 3rd party cookies in the browser, or some other error in the web context has occurred.FirebaseAuthException
thrown if signing in via this method has been disabled in the Firebase Console, or if theprovider
passed is configured improperly.
Parameters
activity | the current Activity
that you intent to launch this flow from |
---|---|
federatedAuthProvider | an FederatedAuthProvider
configured with information about the provider that you intend to link to the
user. |
Returns
- a
Task
with a reference to anAuthResult
with user information upon success
public Task<AuthResult> startActivityForReauthenticateWithProvider (Activity activity, FederatedAuthProvider federatedAuthProvider)
Reauthenticates the user using the mobile browser (either a Custom Chrome Tab or the
device's default browser) using the given provider
. If the calling
activity dies during this operation, use FirebaseAuth.getPendingAuthResult()
to get the outcome of this operation.
Note: this call has a UI associated with it, unlike the majority of calls in FirebaseAuth.
Exceptions
FirebaseAuthInvalidCredentialsException
thrown if the credential generated from the flow is malformed or expired.FirebaseAuthInvalidUserException
thrown if the user has been disabled by an administrator.FirebaseAuthUserCollisionException
thrown if the email that keys the user that is signing in is already in use.FirebaseAuthWebException
thrown if there is an operation already in progress, the pending operation was canceled, there is a problem with 3rd party cookies in the browser, or some other error in the web context has occurred.FirebaseAuthException
thrown if signing in via this method has been disabled in the Firebase Console, or if theprovider
passed is configured improperly.
Parameters
activity | the current Activity
that you intent to launch this flow from |
---|---|
federatedAuthProvider | an FederatedAuthProvider
configured with information about how you intend the user to reauthenticate. |
Returns
- a
Task
with a reference to anAuthResult
with user information upon success
public Task<AuthResult> unlink (String provider)
Detaches credentials from a given provider type from this user. This prevents the user from signing in to this account in the future with credentials from such provider.
Exceptions
FirebaseAuthInvalidUserException
thrown if the current user's account has been disabled, deleted, or its credentials are no longer valid
Parameters
provider | a unique identifier of the type of provider to be unlinked, for example,
FacebookAuthProvider.PROVIDER_ID . |
---|
Returns
Task
ofAuthResult
public Task<Void> updateEmail (String email)
Updates the email address of the user.
Important: this is a security sensitive operation that requires the user to
have recently signed in. If this requirement isn't met, ask the user to authenticate
again and later call
reauthenticate(AuthCredential)
.
In addition, note that the original email address recipient will receive an email that allows them to revoke the email address change, in order to protect them from account hijacking.
Exceptions
FirebaseAuthInvalidCredentialsException
thrown if theemail
address is malformedFirebaseAuthUserCollisionException
thrown if there already exists an account with the givenemail
addressFirebaseAuthInvalidUserException
thrown if the current user's account has been disabled, deleted, or its credentials are no longer validFirebaseAuthRecentLoginRequiredException
thrown if the user's last sign-in time does not meet the security threshold. Usereauthenticate(AuthCredential)
to resolve. This does not apply if the user is anonymous.
public Task<Void> updatePassword (String password)
Updates the password of the user.
Important: this is a security sensitive operation that requires the user to
have recently signed in. If this requirement isn't met, ask the user to authenticate
again and later call
reauthenticate(AuthCredential)
.
Anonymous users who update both their email and password will no longer be anonymous. They will be able to log in with these credentials.
Exceptions
FirebaseAuthWeakPasswordException
thrown if the password is not strong enoughFirebaseAuthInvalidUserException
thrown if the current user's account has been disabled, deleted, or its credentials are no longer validFirebaseAuthRecentLoginRequiredException
thrown if the user's last sign-in time does not meet the security threshold. Usereauthenticate(AuthCredential)
to resolve. This does not apply if the user is anonymous.
public Task<Void> updatePhoneNumber (PhoneAuthCredential credential)
Updates the phone number of the user.
Important: this is a security sensitive operation that requires the user to
have recently signed in. If this requirement isn't met, ask the user to authenticate
again and later call
reauthenticate(AuthCredential)
.
Exceptions
FirebaseAuthUserCollisionException
thrown if there already exists an account with the given phone numberFirebaseAuthInvalidUserException
thrown if the current user's account has been disabled, deleted, or its credentials are no longer validFirebaseAuthRecentLoginRequiredException
thrown if the user's last sign-in time does not meet the security threshold. Usereauthenticate(AuthCredential)
to resolve. This does not apply if the user is anonymous.
public Task<Void> updateProfile (UserProfileChangeRequest request)
Updates the user profile information. Use UserProfileChangeRequest.Builder
to construct the request.
Exceptions
FirebaseAuthInvalidUserException
thrown if the current user's account has been disabled, deleted, or its credentials are no longer valid
public Task<Void> verifyBeforeUpdateEmail (String newEmail)
Calls
verifyBeforeUpdateEmail(String, ActionCodeSettings)
without any
actionCodeSettings
.
public Task<Void> verifyBeforeUpdateEmail (String newEmail, ActionCodeSettings actionCodeSettings)
Sends a verification email to newEmail
. Upon redemption of the link in
the email, this user's email will be changed to newEmail
and that email
will be marked verified.
Parameters
newEmail | the user's new email |
---|---|
actionCodeSettings | the optional ActionCodeSettings
object to allow linking back to your app in the email |
Returns
Task
to track completion of the sending operation.