Properties

app

non-null firebase.app.App

The app associated with the Auth service instance.

Example

var app = auth.app;

currentUser

(firebase.User or null)

The currently signed-in user (or null).

Methods

applyActionCode

applyActionCode(code) returns firebase.Promise containing 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.

Parameter

code

string

A verification code sent to the user.

Returns

non-null firebase.Promise containing void 

checkActionCode

checkActionCode(code) returns firebase.Promise containing non-null firebase.auth.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.

Parameter

code

string

A verification code sent to the user.

Returns

non-null firebase.Promise containing non-null firebase.auth.ActionCodeInfo 

confirmPasswordReset

confirmPasswordReset(code, newPassword) returns firebase.Promise containing 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.

Parameter

code

string

The confirmation code send via email to the user.

newPassword

string

The new password.

Returns

non-null firebase.Promise containing void 

createCustomToken

createCustomToken(uid, developerClaims) returns string

Creates a new custom token (JWT) that can be sent back to a client to use with signInWithCustomToken.

Parameter

uid

string

The uid to use as the subject

developerClaims

Optional

Object

Optional additional claims to include in the payload of the custom token (JWT)

Returns

string The custom token (JWT) for the provided payload.

Deprecated
Use the createCustomToken() method in the Firebase Admin Node.js SDK.

createUserWithEmailAndPassword

createUserWithEmailAndPassword(email, password) returns firebase.Promise containing non-null firebase.User

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.

Parameter

email

string

The user's email address.

password

string

The user's chosen password.

Returns

non-null firebase.Promise containing non-null firebase.User 

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

fetchProvidersForEmail

fetchProvidersForEmail(email) returns firebase.Promise containing non-null Array of string

Gets the list of provider IDs that can be used to sign in for the given email address. Useful for an "identifier-first" sign-in flow.

Error Codes

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

Parameter

email

string

An email address.

Returns

non-null firebase.Promise containing non-null Array of string 

onAuthStateChanged

onAuthStateChanged(nextOrObserver, error, completed) returns function()

Adds an observer for auth state changes.

Parameter

nextOrObserver

(non-null Object or function(nullable firebase.User))

An observer object or a function triggered on change.

error

Optional

function(non-null firebase.auth.Error)

Optional A function triggered on auth error.

completed

Optional

function()

Optional A function triggered when the observer is removed.

Returns

non-null function() The unsubscribe function for the observer.

Example

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

sendPasswordResetEmail

sendPasswordResetEmail(email) returns firebase.Promise containing 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/user-not-found
Thrown if there is no user corresponding to the email address.

Parameter

email

string

The email address with the password to be reset.

Returns

non-null firebase.Promise containing void 

signInAnonymously

signInAnonymously() returns firebase.Promise containing non-null firebase.User

Asynchronously signs in as an anonymous user.

If there is already an anonymous user signed in, that user will be returned; otherwise, a new anonymous user identity will be created and returned.

Error Codes

auth/operation-not-allowed
Thrown if anonymous accounts are not enabled. Enable anonymous accounts in the Firebase Console, under the Auth tab.
Returns

non-null firebase.Promise containing non-null firebase.User 

Example

firebase.auth().signInAnonymously().catch(function(error) {
  // Handle Errors here.
  var errorCode = error.code;
  var errorMessage = error.message;

  if (errorCode === 'auth/operation-not-allowed') {
    alert('You must enable Anonymous auth in the Firebase Console.');
  } else {
    console.error(error);
  }
});

signInWithCredential

signInWithCredential(credential) returns firebase.Promise containing non-null firebase.User

Asynchronously signs in with the given credentials.

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#fetchProvidersForEmail and then asking the user to sign in using one of the returned providers. Once the user is signed in, the original credential can be linked to the user with firebase.User#link.
auth/invalid-credential
Thrown if the credential is malformed or has expired.
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/user-disabled
Thrown if the user corresponding to the given credential has been disabled.
auth/user-not-found
Thrown if signing in with a credential from firebase.auth.EmailAuthProvider#credential and there is no user corresponding to the given email.
auth/wrong-password
Thrown if signing in with a credential from firebase.auth.EmailAuthProvider#credential and the password is invalid for the given email, or if the account corresponding to the email does not have a password set.

Parameter

credential

firebase.auth.AuthCredential

The auth credential.

Value must not be null.

Returns

non-null firebase.Promise containing non-null firebase.User 

Example

firebase.auth().signInWithCredential(credential).catch(function(error) {
  // Handle Errors here.
  var errorCode = error.code;
  var errorMessage = error.message;
  // The email of the user's account used.
  var email = error.email;
  // The firebase.auth.AuthCredential type that was used.
  var credential = error.credential;
  if (errorCode === 'auth/account-exists-with-different-credential') {
    alert('Email already associated with another account.');
    // Handle account linking here, if using.
  } else {
    console.error(error);
  }
 });

signInWithCustomToken

signInWithCustomToken(token) returns firebase.Promise containing non-null firebase.User

Asynchronously signs in using a custom token.

Custom tokens are used to integrate Firebase Auth with existing auth systems, and must be generated by the auth backend.

Fails with an error if the token is invalid, expired, or not accepted by the Firebase Auth service.

Error Codes

auth/custom-token-mismatch
Thrown if the custom token is for a different Firebase App.
auth/invalid-custom-token
Thrown if the custom token format is incorrect.

Parameter

token

string

The custom token to sign in with.

Returns

non-null firebase.Promise containing non-null firebase.User 

Example

firebase.auth().signInWithCustomToken(token).catch(function(error) {
  // Handle Errors here.
  var errorCode = error.code;
  var errorMessage = error.message;
  if (errorCode === 'auth/invalid-custom-token') {
    alert('The token you provided is not valid.');
  } else {
    console.error(error);
  }
});

signInWithEmailAndPassword

signInWithEmailAndPassword(email, password) returns firebase.Promise containing non-null firebase.User

Asynchronously signs in using an email and password.

Fails with an error if the email address and password do not match.

Note: The user's password is NOT the password used to access the user's email account. The email address serves as a unique identifier for the user, and the password is used to access the user's account in your Firebase project.

See also: firebase.auth.Auth#createUserWithEmailAndPassword.

Error Codes

auth/invalid-email
Thrown if the email address is not valid.
auth/user-disabled
Thrown if the user corresponding to the given email has been disabled.
auth/user-not-found
Thrown if there is no user corresponding to the given email.
auth/wrong-password
Thrown if the password is invalid for the given email, or the account corresponding to the email does not have a password set.

Parameter

email

string

The users email address.

password

string

The users password.

Returns

non-null firebase.Promise containing non-null firebase.User 

Example

firebase.auth().signInWithEmailAndPassword(email, password)
    .catch(function(error) {
  // Handle Errors here.
  var errorCode = error.code;
  var errorMessage = error.message;
  if (errorCode === 'auth/wrong-password') {
    alert('Wrong password.');
  } else {
    alert(errorMessage);
  }
  console.log(error);
});

signOut

signOut() returns firebase.Promise containing void

Signs out the current user.

Returns

non-null firebase.Promise containing void 

verifyIdToken

verifyIdToken(idToken) returns firebase.Promise containing Object

Verifies a ID token (JWT). Returns a Promise with the tokens claims. Rejects the promise if the token could not be verified.

Parameter

idToken

string

The ID token (JWT) to verify

Returns

non-null firebase.Promise containing Object The Promise that will be fulfilled after a successful verification

Deprecated
Use the verifyIdToken() method in the Firebase Admin Node.js SDK.

verifyPasswordResetCode

verifyPasswordResetCode(code) returns firebase.Promise containing string

Checks a password reset code sent to the user by email or other out-of-band mechanism.

Returns the user's email address if valid.

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.

Parameter

code

string

A verification code sent to the user.

Returns

non-null firebase.Promise containing string