The Firebase Auth service interface.

Do not call this constructor directly. Instead, use firebase.auth().

See Firebase Authentication for a full guide on how to use the Firebase Auth service.

Index

Type aliases

Persistence

Persistence: string

Properties

app

app: App

The app associated with the Auth service instance.

example
var app = auth.app;

currentUser

currentUser: User | null

The currently signed-in user (or null).

languageCode

languageCode: string | null

The current Auth instance's language code. This is a readable/writable property. When set to null, the default Firebase Console language setting is applied. The language code will propagate to email action templates (password reset, email verification and email change revocation), SMS templates for phone authentication, reCAPTCHA verifier and OAuth popup/redirect operations provided the specified providers support localization with the language code specified.

settings

settings: AuthSettings

The current Auth instance's settings. This is used to edit/read configuration related options like app verification mode for phone authentication.

tenantId

tenantId: string | null

The current Auth instance's tenant ID. This is a readable/writable property. When you set the tenant ID of an Auth instance, all future sign-in/sign-up operations will pass this tenant ID and sign in or sign up users to the specified tenant project. When set to null, users are signed in to the parent project. By default, this is set to null.

example
// Set the tenant ID on Auth instance.
firebase.auth().tenantId = ‘TENANT_PROJECT_ID’;

// All future sign-in request now include tenant ID.
firebase.auth().signInWithEmailAndPassword(email, password)
  .then(function(result) {
    // result.user.tenantId should be ‘TENANT_PROJECT_ID’.
  }).catch(function(error) {
    // Handle error.
  });

Variables

Persistence

Persistence: object

An enumeration of the possible persistence mechanism types.

Type declaration

  • LOCAL: Persistence

    Indicates that the state will be persisted even when the browser window is closed or the activity is destroyed in react-native.

  • NONE: Persistence

    Indicates that the state will only be stored in memory and will be cleared when the window or activity is refreshed.

  • SESSION: Persistence

    Indicates that the state will only persist in current session/tab, relevant to web only, and will be cleared when the tab is closed.

Methods

applyActionCode

  • applyActionCode(code: string): Promise<void>
  • Applies a verification code sent to the user by email or other out-of-band mechanism.

    Error Codes

    auth/expired-action-code
    Thrown if the action code has expired.
    auth/invalid-action-code
    Thrown if the action code is invalid. This can happen if the code is malformed or has already been used.
    auth/user-disabled
    Thrown if the user corresponding to the given action code has been disabled.
    auth/user-not-found
    Thrown if there is no user corresponding to the action code. This may have happened if the user was deleted between when the action code was issued and when this method was called.

    Parameters

    • code: string

      A verification code sent to the user.

    Returns Promise<void>

checkActionCode

  • checkActionCode(code: string): Promise<ActionCodeInfo>
  • Checks a verification code sent to the user by email or other out-of-band mechanism.

    Returns metadata about the code.

    Error Codes

    auth/expired-action-code
    Thrown if the action code has expired.
    auth/invalid-action-code
    Thrown if the action code is invalid. This can happen if the code is malformed or has already been used.
    auth/user-disabled
    Thrown if the user corresponding to the given action code has been disabled.
    auth/user-not-found
    Thrown if there is no user corresponding to the action code. This may have happened if the user was deleted between when the action code was issued and when this method was called.

    Parameters

    • code: string

      A verification code sent to the user.

    Returns Promise<ActionCodeInfo>

confirmPasswordReset

  • confirmPasswordReset(code: string, newPassword: string): Promise<void>
  • Completes the password reset process, given a confirmation code and new password.

    Error Codes

    auth/expired-action-code
    Thrown if the password reset code has expired.
    auth/invalid-action-code
    Thrown if the password reset code is invalid. This can happen if the code is malformed or has already been used.
    auth/user-disabled
    Thrown if the user corresponding to the given password reset code has been disabled.
    auth/user-not-found
    Thrown if there is no user corresponding to the password reset code. This may have happened if the user was deleted between when the code was issued and when this method was called.
    auth/weak-password
    Thrown if the new password is not strong enough.

    Parameters

    • code: string

      The confirmation code send via email to the user.

    • newPassword: string

      The new password.

    Returns Promise<void>

createUserWithEmailAndPassword

  • createUserWithEmailAndPassword(email: string, password: string): Promise<UserCredential>
  • Creates a new user account associated with the specified email address and password.

    On successful creation of the user account, this user will also be signed in to your application.

    User account creation can fail if the account already exists or the password is invalid.

    Note: The email address acts as a unique identifier for the user and enables an email-based password reset. This function will create a new user account and set the initial user password.

    Error Codes

    auth/email-already-in-use
    Thrown if there already exists an account with the given email address.
    auth/invalid-email
    Thrown if the email address is not valid.
    auth/operation-not-allowed
    Thrown if email/password accounts are not enabled. Enable email/password accounts in the Firebase Console, under the Auth tab.
    auth/weak-password
    Thrown if the password is not strong enough.
    example
    firebase.auth().createUserWithEmailAndPassword(email, password)
        .catch(function(error) {
      // Handle Errors here.
      var errorCode = error.code;
      var errorMessage = error.message;
      if (errorCode == 'auth/weak-password') {
        alert('The password is too weak.');
      } else {
        alert(errorMessage);
      }
      console.log(error);
    });

    Parameters

    • email: string

      The user's email address.

    • password: string

      The user's chosen password.

    Returns Promise<UserCredential>

fetchSignInMethodsForEmail

  • fetchSignInMethodsForEmail(email: string): Promise<Array<string>>
  • Gets the list of possible sign in methods for the given email address. This is useful to differentiate methods of sign-in for the same provider, eg. EmailAuthProvider which has 2 methods of sign-in, email/password and email/link.

    Error Codes

    auth/invalid-email
    Thrown if the email address is not valid.

    Parameters

    • email: string

    Returns Promise<Array<string>>

isSignInWithEmailLink

  • isSignInWithEmailLink(emailLink: string): boolean
  • Checks if an incoming link is a sign-in with email link.

    Parameters

    • emailLink: string

    Returns boolean

onAuthStateChanged

  • onAuthStateChanged(nextOrObserver: Observer<any> | function, error?: function, completed?: firebase.Unsubscribe): firebase.Unsubscribe
  • Adds an observer for changes to the user's sign-in state.

    Prior to 4.0.0, this triggered the observer when users were signed in, signed out, or when the user's ID token changed in situations such as token expiry or password change. After 4.0.0, the observer is only triggered on sign-in or sign-out.

    To keep the old behavior, see firebase.auth.Auth.onIdTokenChanged.

    example
    firebase.auth().onAuthStateChanged(function(user) {
      if (user) {
        // User is signed in.
      }
    });

    Parameters

    • nextOrObserver: Observer<any> | function
    • Optional error: function
    • Optional completed: firebase.Unsubscribe

    Returns firebase.Unsubscribe

onIdTokenChanged

  • onIdTokenChanged(nextOrObserver: Observer<any> | function, error?: function, completed?: firebase.Unsubscribe): firebase.Unsubscribe
  • Adds an observer for changes to the signed-in user's ID token, which includes sign-in, sign-out, and token refresh events. This method has the same behavior as firebase.auth.Auth.onAuthStateChanged had prior to 4.0.0.

    example
    firebase.auth().onIdTokenChanged(function(user) {
      if (user) {
        // User is signed in or token was refreshed.
      }
    });

    Parameters

    • nextOrObserver: Observer<any> | function
    • Optional error: function

      Optional A function triggered on auth error.

    • Optional completed: firebase.Unsubscribe

      Optional A function triggered when the observer is removed.

    Returns firebase.Unsubscribe

sendPasswordResetEmail

  • sendPasswordResetEmail(email: string, actionCodeSettings?: ActionCodeSettings | null): Promise<void>
  • Sends a password reset email to the given email address.

    To complete the password reset, call firebase.auth.Auth.confirmPasswordReset with the code supplied in the email sent to the user, along with the new password specified by the user.

    Error Codes

    auth/invalid-email
    Thrown if the email address is not valid.
    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.
    auth/user-not-found
    Thrown if there is no user corresponding to the email address.
    example
    var actionCodeSettings = {
      url: 'https://www.example.com/?email=user@example.com',
      iOS: {
        bundleId: 'com.example.ios'
      },
      android: {
        packageN