User
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.
firebase.auth().onAuthStateChanged((user) => {
if (user) {
console.log('User email: ', user.email);
}
});
Example 2
const user = firebase.auth().currentUser;
if (user) {
console.log('User email: ', user.email);
}
Properties
isAnonymous
</>Returns true if the user is anonymous; that is, the user account was created with
auth#signInAnonymously
and has not been linked to another account
with auth#linkWithCredential
.
isAnonymous: boolean;
phoneNumber
</>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
.
phoneNumber: string | null;
providerId
</>The authentication provider ID for the current user. For example, 'facebook.com', or 'google.com'.
providerId: string;
Methods
getIdToken
</>Returns the users authentication token.
getIdToken(forceRefresh?: undefined | false | true): Promise<string>;
getIdTokenResult
</>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.
getIdTokenResult(forceRefresh?: undefined | false | true): Promise<IdTokenResult>;
linkWithCredential
</>Link the user with a 3rd party credential provider.
linkWithCredential(credential: AuthCredential): Promise<UserCredential>;
linkWithProvider
</>Link the user with a federated 3rd party credential provider (Microsoft, Yahoo).
linkWithProvider(provider: AuthProvider): Promise<UserCredential>;
reauthenticateWithCredential
</>Re-authenticate a user with a third-party authentication provider.
reauthenticateWithCredential(credential: AuthCredential): Promise<UserCredential>;
reauthenticateWithProvider
</>Re-authenticate a user with a federated authentication provider (Microsoft, Yahoo)
reauthenticateWithProvider(provider: AuthProvider): Promise<UserCredential>;
sendEmailVerification
</>Sends a verification email to a user.
sendEmailVerification(actionCodeSettings?: ActionCodeSettings): Promise<void>;
updatePhoneNumber
</>Updates the user's phone number.
updatePhoneNumber(credential: AuthCredential): Promise<void>;
verifyBeforeUpdateEmail
</>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.
verifyBeforeUpdateEmail(email: string, actionCodeSettings?: ActionCodeSettings): Promise<void>;