React Native Firebase
    Preparing search index...

    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.

    Subscribing to the users authentication state.

    firebase.auth().onAuthStateChanged((user) => {
    if (user) {
    console.log('User email: ', user.email);
    }
    });
    const user = firebase.auth().currentUser;

    if (user) {
    console.log('User email: ', user.email);
    }
    interface User {
        displayName: string | null;
        email: string | null;
        emailVerified: boolean;
        isAnonymous: boolean;
        metadata: UserMetadata;
        multiFactor: MultiFactor | null;
        phoneNumber: string | null;
        photoURL: string | null;
        providerData: UserInfo[];
        providerId: string;
        uid: string;
        delete(): Promise<void>;
        getIdToken(forceRefresh?: boolean): Promise<string>;
        getIdTokenResult(forceRefresh?: boolean): Promise<IdTokenResult>;
        linkWithCredential(credential: AuthCredential): Promise<UserCredential>;
        linkWithPopup(provider: AuthProvider): Promise<UserCredential>;
        linkWithRedirect(provider: AuthProvider): Promise<UserCredential>;
        reauthenticateWithCredential(
            credential: AuthCredential,
        ): Promise<UserCredential>;
        reauthenticateWithPopup(provider: AuthProvider): Promise<UserCredential>;
        reauthenticateWithRedirect(provider: AuthProvider): Promise<void>;
        reload(): Promise<void>;
        sendEmailVerification(
            actionCodeSettings?: ActionCodeSettings,
        ): Promise<void>;
        toJSON(): object;
        unlink(providerId: string): Promise<User>;
        updateEmail(email: string): Promise<void>;
        updatePassword(password: string): Promise<void>;
        updatePhoneNumber(credential: AuthCredential): Promise<void>;
        updateProfile(updates: UpdateProfile): Promise<void>;
        verifyBeforeUpdateEmail(
            email: string,
            actionCodeSettings?: ActionCodeSettings,
        ): Promise<void>;
    }
    Index

    Methods

    • Delete the current user.

      await firebase.auth().currentUser.delete();
      

      Returns Promise<void>

      auth/requires-recent-login Thrown if the user's last sign-in time does not meet the security threshold. Use auth.User#reauthenticateWithCredential to resolve. This does not apply if the user is anonymous.

    • Returns the users authentication token.

      // Force a token refresh
      const idToken = await firebase.auth().currentUser.getIdToken(true);

      Parameters

      • OptionalforceRefresh: boolean

        A boolean value which forces Firebase to refresh the token.

      Returns Promise<string>

    • 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);

      Parameters

      • OptionalforceRefresh: boolean

        boolean Force refresh regardless of token expiration.

      Returns Promise<IdTokenResult>

    • 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);

      Parameters

      Returns Promise<UserCredential>

      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/invalid-email Thrown if the email used in a auth.EmailAuthProvider.credential is invalid.

      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.

    • 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);

      Parameters

      Returns Promise<UserCredential>

      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/invalid-email Thrown if the email used in a auth.EmailAuthProvider.credential is invalid.

      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.

    • 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);

      Parameters

      Returns Promise<UserCredential>

      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/invalid-email Thrown if the email used in a auth.EmailAuthProvider.credential is invalid.

      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.

    • 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);

      Parameters

      Returns Promise<UserCredential>

      auth/user-mismatch Thrown if the credential given does not correspond to the user.

      auth/user-not-found Thrown if the credential given does not correspond to any existing 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/invalid-email Thrown if the email used in a auth.EmailAuthProvider.credential is invalid.

      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.

    • 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.

      Parameters

      Returns Promise<UserCredential>

      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);

      Parameters

      Returns Promise<void>

      A promise that resolves with no value.

      auth/user-mismatch Thrown if the credential given does not correspond to the user.

      auth/user-not-found Thrown if the credential given does not correspond to any existing 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/invalid-email Thrown if the email used in a auth.EmailAuthProvider.credential is invalid.

      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.

    • Refreshes the current user.

      await firebase.auth().currentUser.reload();
      

      Returns Promise<void>

    • Sends a verification email to a user.

      await firebase.auth().currentUser.sendEmailVerification({
      handleCodeInApp: true,
      });

      This will Promise reject if the user is anonymous.

      Parameters

      • OptionalactionCodeSettings: ActionCodeSettings

        Any optional additional settings to be set before sending the verification email.

      Returns Promise<void>

      auth/missing-android-pkg-name An Android package name must be provided if the Android app is required to be installed.

      auth/missing-continue-uri A continue URL must be provided in the request.

      auth/missing-ios-bundle-id An iOS bundle ID must be provided if an App Store ID is provided.

      auth/invalid-continue-uri The continue URL provided in the request is invalid.

      auth/unauthorized-continue-uri The domain of the continue URL is not whitelisted. Whitelist the domain in the Firebase console.

    • Returns a JSON-serializable representation of this object.

      const user = firebase.auth().currentUser.toJSON();
      

      Returns object

    • Unlinks a provider from a user account.

      const user = await firebase.auth().currentUser.unlink('facebook.com');
      

      Parameters

      • providerId: string

      Returns Promise<User>

      auth/no-such-provider Thrown if the user does not have this provider linked or when the provider ID given does not exist.

    • 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.

      Parameters

      • email: string

        The users new email address.

      Returns Promise<void>

      auth/invalid-email Thrown if the email used is invalid.

      auth/email-already-in-use Thrown if the email is already used by another user.

      auth/requires-recent-login Thrown if the user's last sign-in time does not meet the security threshold.

    • 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.

      Parameters

      • password: string

        The users new password.

      Returns Promise<void>

      auth/weak-password Thrown if the password is not strong enough.

      auth/requires-recent-login Thrown if the user's last sign-in time does not meet the security threshold.

    • 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.

      Parameters

      Returns Promise<void>

      auth/invalid-verification-code Thrown if the verification code of the credential is not valid.

      auth/invalid-verification-id Thrown if the verification ID of the credential is not valid.

    • Updates a user's profile data.

      await firebase.auth().currentUser.updateProfile({
      displayName: 'Alias',
      });

      Parameters

      Returns Promise<void>

    • 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.

      Parameters

      • email: string
      • OptionalactionCodeSettings: ActionCodeSettings

        Any optional additional settings to be set before sending the verification email.

      Returns Promise<void>

      auth/missing-android-pkg-name An Android package name must be provided if the Android app is required to be installed.

      auth/missing-continue-uri A continue URL must be provided in the request.

      auth/missing-ios-bundle-id An iOS bundle ID must be provided if an App Store ID is provided.

      auth/invalid-continue-uri The continue URL provided in the request is invalid.

      auth/unauthorized-continue-uri The domain of the continue URL is not whitelisted. Whitelist the domain in the Firebase console.

    Properties

    displayName: string | null

    The user's display name (if available).

    email: string | null
    • The user's email address (if available).
    emailVerified: boolean
    • True if the user's email address has been verified.
    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.

    metadata: UserMetadata

    Returns the UserMetadata associated with this user.

    multiFactor: MultiFactor | null

    Returns the MultiFactor associated with this user.

    phoneNumber: string | null

    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.

    photoURL: string | null

    The URL of the user's profile picture (if available).

    providerData: UserInfo[]

    Additional provider-specific information about the user.

    providerId: string

    The authentication provider ID for the current user. For example, 'facebook.com', or 'google.com'.

    uid: string
    • The user's unique ID.