FirebaseUser
abstract class FirebaseUser : Parcelable, UserInfo
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.
Summary
Public constructors |
|---|
Public functions |
|
|---|---|
Task<Void!> |
delete()Deletes the user record from your Firebase project's database. |
abstract String? |
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(forceRefresh: Boolean)Fetches a Firebase Auth ID Token for the user; useful when authenticating against your own backend. |
abstract FirebaseUserMetadata? |
Returns the |
abstract MultiFactor |
Returns a |
abstract String? |
Returns the phone number of the user, as stored in the Firebase project's user database, or |
abstract Uri? |
Returns the URL of this user's main profile picture, as stored in the Firebase project's user database. |
abstract (Mutable)List<UserInfo!> |
Returns a |
abstract String |
Always returns |
abstract String? |
Returns the tenant ID of the current user or |
abstract String |
getUid()Returns a string used to uniquely identify your user in your Firebase project's user database. |
abstract Boolean |
Returns true if the user is anonymous; that is, the user account was created with |
Task<AuthResult!> |
linkWithCredential(credential: AuthCredential)Attaches the given |
Task<Void!> |
reauthenticate(credential: AuthCredential)Reauthenticates the user with the given credential. |
Task<AuthResult!> |
reauthenticateAndRetrieveData(credential: AuthCredential)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!> |
Calls |
Task<Void!> |
sendEmailVerification(actionCodeSettings: ActionCodeSettings)Initiates email verification for the user. |
Task<AuthResult!> |
startActivityForLinkWithProvider(Links the user using the mobile browser (either a Custom Chrome Tab or the device's default browser) to the given |
Task<AuthResult!> |
startActivityForReauthenticateWithProvider(Reauthenticates the user using the mobile browser (either a Custom Chrome Tab or the device's default browser) using the given |
Task<AuthResult!> |
Detaches credentials from a given provider type from this user. |
Task<Void!> |
This function is deprecated. Use |
Task<Void!> |
updatePassword(password: String)Updates the password of the user. |
Task<Void!> |
updatePhoneNumber(credential: PhoneAuthCredential)Updates the phone number of the user. |
Task<Void!> |
updateProfile(request: UserProfileChangeRequest)Updates the user profile information. |
Task<Void!> |
verifyBeforeUpdateEmail(newEmail: String)Calls |
Task<Void!> |
verifyBeforeUpdateEmail(Sends a verification email to |
Inherited functions |
||||
|---|---|---|---|---|
|
||||
|
Public constructors
Public functions
delete
fun delete(): Task<Void!>
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.
FirebaseAuthInvalidUserExceptionthrown if the current user's account has been disabled, deleted, or its credentials are no longer validFirebaseAuthRecentLoginRequiredExceptionthrown if the user's last sign-in time does not meet the security threshold. Usereauthenticateto resolve. This does not apply if the user is anonymous.
getDisplayName
abstract fun getDisplayName(): String?
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.
This field will be automatically populated on account creation if the AuthCredential used on signInWithCredential contained such information.
| See also | |
|---|---|
updateProfile |
getEmail
abstract fun getEmail(): String?
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.
This field will be automatically populated on account creation if the AuthCredential used on signInWithCredential contained such information, or if the account was created with createUserWithEmailAndPassword. 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 createUserWithEmailAndPassword or updateEmail has been called.
If the user also has a password, this email address can be used to sign in into the account using signInWithEmailAndPassword.
This email address is displayed in the Users section of the Firebase console.
| See also | |
|---|---|
updateEmail |
getIdToken
fun getIdToken(forceRefresh: Boolean): Task<GetTokenResult!>
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.
ExceptionsFirebaseAuthInvalidUserExceptionifforceRefresh == true, thrown if the current user's account has been disabled, deleted, or its credentials are no longer valid
| Parameters | |
|---|---|
forceRefresh: Boolean |
force refreshes the token. Should only be set to |
| Returns | |
|---|---|
Task<GetTokenResult!> |
a |
getMetadata
abstract fun getMetadata(): FirebaseUserMetadata?
Returns the FirebaseUserMetadata associated with this user.
getMultiFactor
abstract fun getMultiFactor(): MultiFactor
Returns a MultiFactor instance which is the main entry point for multi-factor related operations on this user.
getPhoneNumber
abstract fun getPhoneNumber(): String?
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.
This field will be automatically populated on account creation if the AuthCredential used on signInWithCredential contained such information. This phone number is displayed in the Users section of the Firebase console.
| See also | |
|---|---|
updatePhoneNumber |
getPhotoUrl
abstract fun getPhotoUrl(): Uri?
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.
This field will be automatically populated on account creation if the AuthCredential used on signInWithCredential contained such information.
| See also | |
|---|---|
updateProfile |
getProviderData
abstract fun getProviderData(): (Mutable)List<UserInfo!>
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.
getTenantId
abstract fun getTenantId(): String?
Returns the tenant ID of the current user or null if this user isn't associated with a tenant project.
getUid
abstract fun getUid(): String
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.
isAnonymous
abstract fun isAnonymous(): Boolean
Returns true if the user is anonymous; that is, the user account was created with signInAnonymously and has not been linked to another account with linkWithCredential.
linkWithCredential
fun linkWithCredential(credential: AuthCredential): Task<AuthResult!>
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.
FirebaseAuthWeakPasswordExceptionthrown ifcredential instanceof EmailAuthCredentialand the password is not strong enoughFirebaseAuthInvalidCredentialsExceptionthrown if thecredentialis malformed or expiredFirebaseAuthUserCollisionExceptionthrown if there is another user account associated with the givencredentialFirebaseAuthInvalidUserExceptionthrown if the current user's account has been disabled, deleted, or its credentials are no longer validFirebaseAuthRecentLoginRequiredExceptionthrown ifcredential instanceof EmailAuthCredentialand if the user's last sign-in time does not meet the security threshold. Usereauthenticateto resolve. This does not apply if the user is anonymous.FirebaseAuthExceptionthrown if there is an attempt to link a provider that is already linked to this account or if an internal error occurs
| Parameters | |
|---|---|
credential: AuthCredential |
a valid credential of a type not yet linked to this user |
| Returns | |
|---|---|
Task<AuthResult!> |
|
reauthenticate
fun reauthenticate(credential: AuthCredential): Task<Void!>
Reauthenticates the user with the given credential. This is useful for operations that require a recent sign-in, to prevent or resolve a FirebaseAuthRecentLoginRequiredException.
FirebaseAuthInvalidUserExceptionthrown if the current user's account has been disabled or deletedFirebaseAuthInvalidCredentialsExceptionthrown if thecredentialis malformed or has expired, or if it corresponds to another existing user's account. Inspect the error code to desambiguate.
| Parameters | |
|---|---|
credential: AuthCredential |
authentication credential that must be valid for the current user. |
reauthenticateAndRetrieveData
fun reauthenticateAndRetrieveData(credential: AuthCredential): Task<AuthResult!>
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.
FirebaseAuthInvalidUserExceptionthrown if the current user's account has been disabled or deletedFirebaseAuthInvalidCredentialsExceptionthrown if thecredentialis malformed or has expired, or if it corresponds to another existing user's account. Inspect the error code to desambiguate.
| Parameters | |
|---|---|
credential: AuthCredential |
authentication credential that must be valid for the current user. |
| Returns | |
|---|---|
Task<AuthResult!> |
|
reload
fun reload(): Task<Void!>
Manually refreshes the data of the current user (for example, attached providers, display name, and so on).
ExceptionsFirebaseAuthInvalidUserExceptionthrown if the current user's account has been disabled, deleted, or its credentials are no longer valid
sendEmailVerification
fun sendEmailVerification(): Task<Void!>
Calls sendEmailVerification with null actionCodeSettings.
sendEmailVerification
fun sendEmailVerification(actionCodeSettings: ActionCodeSettings): Task<Void!>
Initiates email verification for the user. Takes in an ActionCodeSettings to allow linking back to your app in the email.
startActivityForLinkWithProvider
fun startActivityForLinkWithProvider(
activity: Activity,
federatedAuthProvider: FederatedAuthProvider
): Task<AuthResult!>
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 getPendingAuthResult to get the outcome of this operation.
Note: this call has a UI associated with it, unlike the majority of calls in FirebaseAuth.
ExceptionsFirebaseAuthInvalidCredentialsExceptionthrown if the credential generated from the flow is malformed or expired.FirebaseAuthInvalidUserExceptionthrown if the user has been disabled by an administrator.FirebaseAuthUserCollisionExceptionthrown if the email that keys the user that is signing in is already in use.FirebaseAuthWebExceptionthrown 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.FirebaseAuthExceptionthrown if signing in via this method has been disabled in the Firebase Console, or if theproviderpassed is configured improperly.
| Parameters | |
|---|---|
activity: Activity |
the current |
federatedAuthProvider: FederatedAuthProvider |
an |
| Returns | |
|---|---|
Task<AuthResult!> |
a |
startActivityForReauthenticateWithProvider
fun startActivityForReauthenticateWithProvider(
activity: Activity,
federatedAuthProvider: FederatedAuthProvider
): Task<AuthResult!>
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 getPendingAuthResult to get the outcome of this operation.
Note: this call has a UI associated with it, unlike the majority of calls in FirebaseAuth.
ExceptionsFirebaseAuthInvalidCredentialsExceptionthrown if the credential generated from the flow is malformed or expired.FirebaseAuthInvalidUserExceptionthrown if the user has been disabled by an administrator.FirebaseAuthUserCollisionExceptionthrown if the email that keys the user that is signing in is already in use.FirebaseAuthWebExceptionthrown 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.FirebaseAuthExceptionthrown if signing in via this method has been disabled in the Firebase Console, or if theproviderpassed is configured improperly.
| Parameters | |
|---|---|
activity: Activity |
the current |
federatedAuthProvider: FederatedAuthProvider |
an |
| Returns | |
|---|---|
Task<AuthResult!> |
a |
unlink
fun unlink(provider: String): Task<AuthResult!>
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.
ExceptionsFirebaseAuthInvalidUserExceptionthrown if the current user's account has been disabled, deleted, or its credentials are no longer valid
| Parameters | |
|---|---|
provider: String |
a unique identifier of the type of provider to be unlinked, for example, |
| Returns | |
|---|---|
Task<AuthResult!> |
|
updateEmail
funupdateEmail(email: String): Task<Void!>
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.
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.
ExceptionsFirebaseAuthInvalidCredentialsExceptionthrown if theemailaddress is malformedFirebaseAuthUserCollisionExceptionthrown if there already exists an account with the givenemailaddressFirebaseAuthInvalidUserExceptionthrown if the current user's account has been disabled, deleted, or its credentials are no longer validFirebaseAuthRecentLoginRequiredExceptionthrown if the user's last sign-in time does not meet the security threshold. Usereauthenticateto resolve. This does not apply if the user is anonymous.FirebaseAuthExceptionthrown with code OPERATION_NOT_ALLOWED if Email Enumeration Protection is enabled.
updatePassword
fun updatePassword(password: String): Task<Void!>
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.
Anonymous users who update both their email and password will no longer be anonymous. They will be able to log in with these credentials.
ExceptionsFirebaseAuthWeakPasswordExceptionthrown if the password is not strong enoughFirebaseAuthInvalidUserExceptionthrown if the current user's account has been disabled, deleted, or its credentials are no longer validFirebaseAuthRecentLoginRequiredExceptionthrown if the user's last sign-in time does not meet the security threshold. Usereauthenticateto resolve. This does not apply if the user is anonymous.
updatePhoneNumber
fun updatePhoneNumber(credential: PhoneAuthCredential): Task<Void!>
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.
FirebaseAuthUserCollisionExceptionthrown if there already exists an account with the given phone numberFirebaseAuthInvalidUserExceptionthrown if the current user's account has been disabled, deleted, or its credentials are no longer validFirebaseAuthRecentLoginRequiredExceptionthrown if the user's last sign-in time does not meet the security threshold. Usereauthenticateto resolve. This does not apply if the user is anonymous.
updateProfile
fun updateProfile(request: UserProfileChangeRequest): Task<Void!>
Updates the user profile information. Use UserProfileChangeRequest.Builder to construct the request.
FirebaseAuthInvalidUserExceptionthrown if the current user's account has been disabled, deleted, or its credentials are no longer valid
verifyBeforeUpdateEmail
fun verifyBeforeUpdateEmail(newEmail: String): Task<Void!>
Calls verifyBeforeUpdateEmail without any
actionCodeSettings.
verifyBeforeUpdateEmail
fun verifyBeforeUpdateEmail(
newEmail: String,
actionCodeSettings: ActionCodeSettings?
): Task<Void!>
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: String |
the user's new email |
actionCodeSettings: ActionCodeSettings? |
the optional |