Returns a firebase.auth.IdTokenResult object which contains the ID token JWT string and other helper properties for getting different data associated with the token as well as all the decoded payload claims.
// Force a token refresh
const idTokenResult = await firebase.auth().currentUser.getIdTokenResult(true);
OptionalforceRefresh: booleanboolean Force refresh regardless of token expiration.
Link the user with a 3rd party credential provider.
const facebookCredential = firebase.auth.FacebookAuthProvider.credential('access token from Facebook');
const userCredential = await firebase.auth().currentUser.linkWithCredential(facebookCredential);
A created AuthCredential.
auth/provider-already-linked Thrown if the provider has already been linked to the user. This error is thrown even if this is not the same provider's account that is currently linked to the user.
auth/invalid-credential Thrown if the provider's credential is not valid. This can happen if it has already expired when calling link, or if it used invalid token(s). See the Firebase documentation for your provider, and make sure you pass in the correct parameters to the credential method.
auth/credential-already-in-use Thrown if the account corresponding to the credential already exists among your users, or is already linked to a Firebase User.
auth/email-already-in-use Thrown if the email corresponding to the credential already exists among your users.
auth/operation-not-allowed Thrown if you have not enabled the provider in the Firebase Console. Go to the Firebase Console for your project, in the Auth section and the Sign in Method tab and configure the provider.
auth/wrong-password Thrown if the password used in a auth.EmailAuthProvider.credential is not correct or when the user associated with the email does not have a password.
auth/invalid-verification-code Thrown if the credential is a auth.PhoneAuthProvider.credential and the verification code of the credential is not valid.
auth/invalid-verification-id Thrown if the credential is a auth.PhoneAuthProvider.credential and the verification ID of the credential is not valid.
on iOS NativeFirebaseAuthError, on Android NativeFirebaseError
Link the user with a federated 3rd party credential provider (Microsoft, Yahoo). The APIs here are the web-compatible linkWithPopup and linkWithRedirect but both share the same underlying native SDK behavior and may be used interchangably.
const provider = new firebase.auth.OAuthProvider('microsoft.com');
const userCredential = await firebase.auth().currentUser.linkWithPopup(provider);
A created AuthProvider.
auth/provider-already-linked Thrown if the provider has already been linked to the user. This error is thrown even if this is not the same provider's account that is currently linked to the user.
auth/invalid-credential Thrown if the provider's credential is not valid. This can happen if it has already expired when calling link, or if it used invalid token(s). See the Firebase documentation for your provider, and make sure you pass in the correct parameters to the credential method.
auth/credential-already-in-use Thrown if the account corresponding to the credential already exists among your users, or is already linked to a Firebase User.
auth/email-already-in-use Thrown if the email corresponding to the credential already exists among your users.
auth/operation-not-allowed Thrown if you have not enabled the provider in the Firebase Console. Go to the Firebase Console for your project, in the Auth section and the Sign in Method tab and configure the provider.
auth/wrong-password Thrown if the password used in a auth.EmailAuthProvider.credential is not correct or when the user associated with the email does not have a password.
auth/invalid-verification-code Thrown if the credential is a auth.PhoneAuthProvider.credential and the verification code of the credential is not valid.
auth/invalid-verification-id Thrown if the credential is a auth.PhoneAuthProvider.credential and the verification ID of the credential is not valid.
on iOS NativeFirebaseAuthError, on Android NativeFirebaseError
Link the user with a federated 3rd party credential provider (Microsoft, Yahoo). The APIs here are the web-compatible linkWithPopup and linkWithRedirect but both share the same underlying native SDK behavior and may be used interchangably.
const provider = new firebase.auth.OAuthProvider('microsoft.com');
const userCredential = await firebase.auth().currentUser.linkWithRedirect(provider);
A created AuthProvider.
auth/provider-already-linked Thrown if the provider has already been linked to the user. This error is thrown even if this is not the same provider's account that is currently linked to the user.
auth/invalid-credential Thrown if the provider's credential is not valid. This can happen if it has already expired when calling link, or if it used invalid token(s). See the Firebase documentation for your provider, and make sure you pass in the correct parameters to the credential method.
auth/credential-already-in-use Thrown if the account corresponding to the credential already exists among your users, or is already linked to a Firebase User.
auth/email-already-in-use Thrown if the email corresponding to the credential already exists among your users.
auth/operation-not-allowed Thrown if you have not enabled the provider in the Firebase Console. Go to the Firebase Console for your project, in the Auth section and the Sign in Method tab and configure the provider.
auth/wrong-password Thrown if the password used in a auth.EmailAuthProvider.credential is not correct or when the user associated with the email does not have a password.
auth/invalid-verification-code Thrown if the credential is a auth.PhoneAuthProvider.credential and the verification code of the credential is not valid.
auth/invalid-verification-id Thrown if the credential is a auth.PhoneAuthProvider.credential and the verification ID of the credential is not valid.
on iOS NativeFirebaseAuthError, on Android NativeFirebaseError
Re-authenticate a user with a third-party authentication provider.
const facebookCredential = firebase.auth.FacebookAuthProvider.credential('access token from Facebook');
const userCredential = await firebase.auth().currentUser.reauthenticateWithCredential(facebookCredential);
A created AuthCredential.
auth/invalid-credential Thrown if the provider's credential is not valid. This can happen if it has already expired when calling link, or if it used invalid token(s). See the Firebase documentation for your provider, and make sure you pass in the correct parameters to the credential method.
auth/wrong-password Thrown if the password used in a auth.EmailAuthProvider.credential is not correct or when the user associated with the email does not have a password.
Re-authenticate a user with a federated authentication provider (Microsoft, Yahoo). For native platforms, this will open a browser window. pop-up equivalent on native platforms.
The auth provider.
A promise that resolves with the user credentials.
Re-authenticate a user with a federated authentication provider (Microsoft, Yahoo). For native platforms, this will open a browser window.
const provider = new firebase.auth.OAuthProvider('microsoft.com');
const userCredential = await firebase.auth().currentUser.reauthenticateWithProvider(provider);
A created AuthProvider.
A promise that resolves with no value.
auth/invalid-credential Thrown if the provider's credential is not valid. This can happen if it has already expired when calling link, or if it used invalid token(s). See the Firebase documentation for your provider, and make sure you pass in the correct parameters to the credential method.
auth/wrong-password Thrown if the password used in a auth.EmailAuthProvider.credential is not correct or when the user associated with the email does not have a password.
Sends a verification email to a user.
await firebase.auth().currentUser.sendEmailVerification({
handleCodeInApp: true,
});
This will Promise reject if the user is anonymous.
OptionalactionCodeSettings: ActionCodeSettingsAny optional additional settings to be set before sending the verification email.
Unlinks a provider from a user account.
const user = await firebase.auth().currentUser.unlink('facebook.com');
Updates the user's email address.
See Firebase docs for more information on security & email validation.
await firebase.auth().currentUser.updateEmail('[email protected]');
This will Promise reject if the user is anonymous.
The users new email address.
Updates the users password.
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 then call firebase.User#reauthenticate.
await firebase.auth().currentUser.updatePassword('654321');
This will Promise reject is the user is anonymous.
The users new password.
Updates the user's phone number.
See Firebase docs for more information on security & email validation.
const snapshot = await firebase.auth().verifyPhoneNumber('+4423456789')
.on(...); // See PhoneAuthListener - wait for successful verification
const credential = firebase.auth.PhoneAuthProvider.credential(snapshot.verificationId, snapshot.code);
// Update user with new verified phone number
await firebase.auth().currentUser.updatePhoneNumber(credential);
This will Promise reject is the user is anonymous.
A created PhoneAuthCredential.
Updates a user's profile data.
await firebase.auth().currentUser.updateProfile({
displayName: 'Alias',
});
Sends a link to the user's email address, when clicked, the user's Authentication email address will be updated to whatever was passed as the first argument.
await firebase.auth().currentUser.verifyBeforeUpdateEmail(
'[email protected]',
{
handleCodeInApp: true,
});
This will Promise reject if the user is anonymous.
OptionalactionCodeSettings: ActionCodeSettingsAny optional additional settings to be set before sending the verification email.
The user's display name (if available).
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.
Returns the UserMetadata associated with this user.
Returns the MultiFactor associated with this user.
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 User#updatePhoneNumber.
The URL of the user's profile picture (if available).
Additional provider-specific information about the user.
The authentication provider ID for the current user. For example, 'facebook.com', or 'google.com'.
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.
Example 1
Subscribing to the users authentication state.
Example 2