Konsola git

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

An enumeration of the possible persistence mechanism types.

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.

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

getRedirectResult

  • getRedirectResult(): Promise<UserCredential>
  • Returns a UserCredential from the redirect-based sign-in flow.

    If sign-in succeeded, returns the signed in user. If sign-in was unsuccessful, fails with an error. If no redirect operation was called, returns a UserCredential with a null User.

    Error Codes

    auth/account-exists-with-different-credential
    Thrown if there already exists an account with the email address asserted by the credential. Resolve this by calling firebase.auth.Auth.fetchSignInMethodsForEmail with the error.email and then asking the user to sign in using one of the returned providers. Once the user is signed in, the original credential retrieved from the error.credential can be linked to the user with firebase.User.linkWithCredential to prevent the user from signing in again to the original provider via popup or redirect. If you are using redirects for sign in, save the credential in session storage and then retrieve on redirect and repopulate the credential using for example firebase.auth.GoogleAuthProvider.credential depending on the credential provider id and complete the link.
    auth/auth-domain-config-required
    Thrown if authDomain configuration is not provided when calling firebase.initializeApp(). Check Firebase Console for instructions on determining and passing that field.
    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. For example, this error could be thrown if you are upgrading an anonymous user to a Google user by linking a Google credential to it and the Google credential used is already associated with an existing Firebase Google user. An error.email and error.credential (firebase.auth.AuthCredential) fields are also provided. You can recover from this error by signing in with that credential directly via firebase.auth.Auth.signInWithCredential.
    auth/email-already-in-use
    Thrown if the email corresponding to the credential already exists among your users. When thrown while linking a credential to an existing user, an error.email and error.credential (firebase.auth.AuthCredential) fields are also provided. You have to link the credential to the existing user with that email if you wish to continue signing in with that credential. To do so, call firebase.auth.Auth.fetchSignInMethodsForEmail, sign in to error.email via one of the providers returned and then firebase.User.linkWithCredential the original credential to that newly signed in user.
    auth/operation-not-allowed
    Thrown if the type of account corresponding to the credential is not enabled. Enable the account type in the Firebase Console, under the Auth tab.
    auth/operation-not-supported-in-this-environment
    Thrown if this operation is not supported in the environment your application is running on. "location.protocol" must be http or https.
    auth/timeout
    Thrown typically if the app domain is not authorized for OAuth operations for your Firebase project. Edit the list of authorized domains from the Firebase console.
    example
    // First, we perform the signInWithRedirect.
    // Creates the provider object.
    var provider = new firebase.auth.FacebookAuthProvider();
    // You can add additional scopes to the provider:
    provider.addScope('email');
    provider.addScope('user_friends');
    // Sign in with redirect:
    auth.signInWithRedirect(provider)
    ////////////////////////////////////////////////////////////
    // The user is redirected to the provider's