You are on page 1of 17

12/9/2017 Interface: Auth | Firebase

Enumeration
Persistence
Properties
Persistence

rebase.auth.Auth
INTERFACESTATIC

The Firebase Auth service interface.

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

SeeFirebase Authenticationfor a full guide on how to use the Firebase Auth service.

Enumeration

Persistence
STATIC
string

An enumeration of the possible persistence mechanism types.

Value

LOCAL

Indicates that the state will be persisted even when the


browser window is closed or the activity is destroyed in
react-native.

NONE

Indicates that the state will only be stored in memory and


will be cleared when the window or activity is refreshed.

SESSION

Indicates that the state will only persist in current


session/tab, relevant to web only, and will be cleared
when the tab is closed.

Properties

Persistence
STATIC
string

An enumeration of the possible persistence mechanism types.

Value

LOCAL

Indicates that the state will be persisted even when the


browser window is closed or the activity is destroyed in
react-native.

https://firebase.google.com/docs/reference/js/firebase.auth.Auth 1/17
12/9/2017 Interface: Auth | Firebase

NONE

Indicates that the state will only be stored in memory and


will be cleared when the window or activity is refreshed.

SESSION

Indicates that the state will only persist in current


session/tab, relevant to web only, and will be cleared
when the tab is closed.

app
non-null firebase.app.App

Theappassociated with the Auth service instance.

Example

var app = auth.app;

currentUser
(firebase.User or null)

The currently signed-in user (or null).

languageCode
(string or 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 verication and email change
revocation), SMS templates for phone authentication, reCAPTCHA verier and OAuth popup/redirect operations provided the specied
providers support localization with the language code specied.

Methods

applyActionCode
applyActionCode(code) returns firebase.Promisecontaining void

Applies a verication 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

https://firebase.google.com/docs/reference/js/firebase.auth.Auth 2/17
12/9/2017 Interface: Auth | Firebase

string
A verication code sent to the user.

Returns

non-null firebase.Promise containing void

checkActionCode
checkActionCode(code) returns firebase.Promisecontaining non-null firebase.auth.ActionCodeInfo

Checks a verication 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 verication code sent to the user.

Returns

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

conrmPasswordReset
confirmPasswordReset(code, newPassword) returns firebase.Promise containing void

Completes the password reset process, given a conrmation 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.

https://firebase.google.com/docs/reference/js/firebase.auth.Auth 3/17
12/9/2017 Interface: Auth | Firebase

auth/weak-password

Thrown if the new password is not strong enough.

Parameter

code

string
The conrmation code send via email to the user.

newPassword

string
The new password.

Returns

non-null firebase.Promise containing void

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

Creates a new user account associated with the specied 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 identier 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

https://firebase.google.com/docs/reference/js/firebase.auth.Auth 4/17
12/9/2017 Interface: Auth | Firebase

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.Promisecontaining 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 "identier-rst" sign-in ow.

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

getRedirectResult
getRedirectResult() returns firebase.Promisecontaining non-null firebase.auth.UserCredential

Returns a UserCredential from the redirect-based sign-in ow.

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
callingrebase.auth.Auth#fetchProvidersForEmailwith 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
withrebase.User#linkWithCredentialto 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 rebase.auth.GoogleAuthProvider#credential depending on the credential provider id and complete the link.

auth/auth-domain-cong-required

Thrown if authDomain conguration is not provided when calling rebase.initializeApp(). Check Firebase Console for instructions
on determining and passing that eld.

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 (rebase.auth.AuthCredential) elds are also provided. You can recover from this error by
signing in with that credential directly viarebase.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 (rebase.auth.AuthCredential) elds 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,

https://firebase.google.com/docs/reference/js/firebase.auth.Auth 5/17
12/9/2017 Interface: Auth | Firebase

callrebase.auth.Auth#fetchProvidersForEmail, sign in to error.email via one of the providers returned and


thenrebase.User#linkWithCredentialthe 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.

Returns

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

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 sign in flow...
////////////////////////////////////////////////////////////
// Then redirected back to the app, where we check the redirect result:
auth.getRedirectResult().then(function(result) {
// The firebase.User instance:
var user = result.user;
// The Facebook firebase.auth.AuthCredential containing the Facebook
// access token:
var credential = result.credential;
// As this API can be used for sign-in, linking and reauthentication,
// check the operationType to determine what triggered this redirect
// operation.
var operationType = result.operationType;
}, function(error) {
// The provider's account email, can be used in case of
// auth/account-exists-with-different-credential to fetch the providers
// linked to the email:
var email = error.email;
// The provider's credential:
var credential = error.credential;
// In case of auth/account-exists-with-different-credential error,
// you can fetch the providers using this:
if (error.code === 'auth/account-exists-with-different-credential') {
auth.fetchProvidersForEmail(email).then(function(providers) {
// The returned 'providers' is a list of the available providers
// linked to the email address. Please refer to the guide for a more
// complete explanation on how to recover from this error.
});
}
});

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

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, seerebase.auth.Auth#onIdTokenChanged.

Parameter

nextOrObserver

(non-null Object or function(nullablerebase.User))


An observer object or a function triggered on change.

error

https://firebase.google.com/docs/reference/js/firebase.auth.Auth 6/17
12/9/2017 Interface: Auth | Firebase

Optional
function(non-nullrebase.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.
}
});

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

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 asrebase.auth.Auth#onAuthStateChangedhad prior to 4.0.0.

Parameter

nextOrObserver

(non-null Object or function(nullablerebase.User))


An observer object or a function triggered on change.

error

Optional
function(non-nullrebase.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().onIdTokenChanged(function(user) {
if (user) {
// User is signed in or token was refreshed.
}
});

sendPasswordResetEmail
sendPasswordResetEmail(email, actionCodeSettings) returns firebase.Promisecontaining void

Sends a password reset email to the given email address.

https://firebase.google.com/docs/reference/js/firebase.auth.Auth 7/17
12/9/2017 Interface: Auth | Firebase

To complete the password reset, callrebase.auth.Auth#conrmPasswordResetwith the code supplied in the email sent to the user,
along with the new password specied 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.

Parameter

email

string
The email address with the password to be reset.

actionCodeSettings

Optional
rebase.auth.ActionCodeSettings
The action code settings. If specied, the state/continue
URL will be set as the "continueUrl" parameter in the
password reset link. The default password reset landing
page will use this to display a link to go back to the app if
it is installed. If the actionCodeSettings is not specied,
no URL is appended to the action URL. The state URL
provided must belong to a domain that is whitelisted by
the developer in the console. Otherwise an error will be
thrown. Mobile app redirects will only be applicable if the
developer congures and accepts the Firebase Dynamic
Links terms of condition. The Android package name and
iOS bundle ID will be respected only if they are congured
in the same Firebase Auth project used.
Value may be null.

Returns

non-null firebase.Promise containing void

Example

var actionCodeSettings = {
url: 'https://www.example.com/?email=user@example.com',
iOS: {
bundleId: 'com.example.ios'
},
android: {
packageName: 'com.example.android',
installApp: true,
minimumVersion: '12'

https://firebase.google.com/docs/reference/js/firebase.auth.Auth 8/17
12/9/2017 Interface: Auth | Firebase
minimumVersion: '12'
},
handleCodeInApp: true
};
firebase.auth().sendPasswordResetEmail(
'user@example.com', actionCodeSettings)
.then(function() {
// Password reset email sent.
})
.catch(function(error) {
// Error occurred. Inspect error.code.
});

setPersistence
setPersistence(persistence) returns firebase.Promisecontaining void

Changes the current type of persistence on the current Auth instance for the currently saved Auth session and applies this type of
persistence for future sign-in requests, including sign-in with redirect requests. This will return a promise that will resolve once the state
nishes copying from one type of storage to the other. Calling a sign-in method after changing persistence will wait for that persistence
change to complete before applying it on the new Auth state.

This makes it easy for a user signing in to specify whether their session should be remembered or not. It also makes it easier to never
persist the Auth state for applications that are shared by other users or have sensitive data.

The default for web browser apps and React Native apps is 'local' (provided the browser supports this mechanism) whereas it is 'none'
for Node.js backend apps.

Error Codes (thrown synchronously)

auth/invalid-persistence-type

Thrown if the specied persistence type is invalid.

auth/unsupported-persistence-type

Thrown if the current environment does not support the specied persistence type.

Parameter

persistence

rebase.auth.Auth.Persistence
The auth state persistence mechanism.
Value must not be null.

Returns

non-null firebase.Promise containing void

Example

firebase.auth().setPersistence(firebase.auth.Auth.Persistence.SESSION)
.then(function() {
// Existing and future Auth states are now persisted in the current
// session only. Closing the window would clear any existing state even if
// a user forgets to sign out.
});

signInAndRetrieveDataWithCredential
signInAndRetrieveDataWithCredential(credential) returns firebase.Promisecontaining non-null firebase.auth.UserCredential

Asynchronously signs in with the given credentials, and returns any available additional user information, such as user name.

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
callingrebase.auth.Auth#fetchProvidersForEmailand 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 withrebase.User#linkWithCredential.

auth/invalid-credential

https://firebase.google.com/docs/reference/js/firebase.auth.Auth 9/17
12/9/2017 Interface: Auth | Firebase

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 rebase.auth.EmailAuthProvider#credential and there is no user corresponding to the
given email.

auth/wrong-password

Thrown if signing in with a credential from rebase.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.

auth/invalid-verication-code

Thrown if the credential is a rebase.auth.PhoneAuthProvider#credential and the verication code of the credential is not valid.

auth/invalid-verication-id

Thrown if the credential is a rebase.auth.PhoneAuthProvider#credential and the verication ID of the credential is not valid.

Parameter

credential

rebase.auth.AuthCredential
The auth credential.
Value must not be null.

Returns

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

Example

firebase.auth().signInAndRetrieveDataWithCredential(credential)
.then(function(userCredential) {
console.log(userCredential.additionalUserInfo.username);
});

signInAnonymously
signInAnonymously() returns firebase.Promisecontaining 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;

https://firebase.google.com/docs/reference/js/firebase.auth.Auth 10/17
12/9/2017 Interface: Auth | Firebase
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.Promisecontaining 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
callingrebase.auth.Auth#fetchProvidersForEmailand 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 withrebase.User#linkWithCredential.

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 rebase.auth.EmailAuthProvider#credential and there is no user corresponding to the
given email.

auth/wrong-password

Thrown if signing in with a credential from rebase.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.

auth/invalid-verication-code

Thrown if the credential is a rebase.auth.PhoneAuthProvider#credential and the verication code of the credential is not valid.

auth/invalid-verication-id

Thrown if the credential is a rebase.auth.PhoneAuthProvider#credential and the verication ID of the credential is not valid.

Parameter

credential

rebase.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;

https://firebase.google.com/docs/reference/js/firebase.auth.Auth 11/17
12/9/2017 Interface: Auth | Firebase
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.Promisecontaining 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
identier for the user, and the password is used to access the user's account in your Firebase project.

See also:rebase.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.

https://firebase.google.com/docs/reference/js/firebase.auth.Auth 12/17
12/9/2017 Interface: Auth | Firebase

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

signInWithPhoneNumber
signInWithPhoneNumber(phoneNumber, applicationVerifier) returns firebase.Promisecontaining non-null firebase.auth.ConfirmationResult

Asynchronously signs in using a phone number. This method sends a code via SMS to the given phone number, and returns
arebase.auth.ConrmationResult. After the user provides the code sent to their phone,
callrebase.auth.ConrmationResult#conrmwith the code to sign the user in.

For abuse prevention, this method also requires arebase.auth.ApplicationVerier. The Firebase Auth SDK includes a reCAPTCHA-
based implementation,rebase.auth.RecaptchaVerier.

Error Codes

auth/captcha-check-failed

Thrown if the reCAPTCHA response token was invalid, expired, or if this method was called from a non-whitelisted domain.

auth/invalid-phone-number

Thrown if the phone number has an invalid format.

auth/missing-phone-number

Thrown if the phone number is missing.

auth/quota-exceeded

Thrown if the SMS quota for the Firebase project has been exceeded.

auth/user-disabled

Thrown if the user corresponding to the given phone number has been disabled.

auth/operation-not-allowed

https://firebase.google.com/docs/reference/js/firebase.auth.Auth 13/17
12/9/2017 Interface: Auth | Firebase

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 theSign in Methodtab and congure the provider.

Parameter

phoneNumber

string
The user's phone number in E.164 format (e.g.
+16505550101).

applicationVerier

rebase.auth.ApplicationVerier
Value must not be null.

Returns

non-null firebase.Promise containing non-nullfirebase.auth.ConfirmationResult

Example

// 'recaptcha-container' is the ID of an element in the DOM.


var applicationVerifier = new firebase.auth.RecaptchaVerifier(
'recaptcha-container');
firebase.auth().signInWithPhoneNumber(phoneNumber, applicationVerifier)
.then(function(confirmationResult) {
var verificationCode = window.prompt('Please enter the verification ' +
'code that was sent to your mobile device.');
return confirmationResult.confirm(verificationCode);
})
.catch(function(error) {
// Handle Errors here.
});

signInWithPopup
signInWithPopup(provider) returns firebase.Promisecontaining non-null firebase.auth.UserCredential

Authenticates a Firebase client using a popup-based OAuth authentication ow.

If succeeds, returns the signed in user along with the provider's credential. If sign in was unsuccessful, returns an error object
containing additional information about the error.

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
callingrebase.auth.Auth#fetchProvidersForEmailwith 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
withrebase.User#linkWithCredentialto 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 rebase.auth.GoogleAuthProvider#credential depending on the credential provider id and complete the link.

auth/auth-domain-cong-required

Thrown if authDomain conguration is not provided when calling rebase.initializeApp(). Check Firebase Console for instructions
on determining and passing that eld.

auth/cancelled-popup-request

Thrown if successive popup operations are triggered. Only one popup request is allowed at one time. All the popups would fail
with this error except for the last one.

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.

https://firebase.google.com/docs/reference/js/firebase.auth.Auth 14/17
12/9/2017 Interface: Auth | Firebase

auth/popup-blocked

Thrown if the popup was blocked by the browser, typically when this operation is triggered outside of a click handler.

auth/popup-closed-by-user

Thrown if the popup window is closed by the user without completing the sign in to the provider.

auth/unauthorized-domain

Thrown if the app domain is not authorized for OAuth operations for your Firebase project. Edit the list of authorized domains from
the Firebase console.

Parameter

provider

rebase.auth.AuthProvider
The provider to authenticate. The provider has to be an
OAuth provider. Non-OAuth providers
likerebase.auth.EmailAuthProviderwill throw an error.
Value must not be null.

Returns

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

Example

// 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 popup:
auth.signInWithPopup(provider).then(function(result) {
// The firebase.User instance:
var user = result.user;
// The Facebook firebase.auth.AuthCredential containing the Facebook
// access token:
var credential = result.credential;
}, function(error) {
// The provider's account email, can be used in case of
// auth/account-exists-with-different-credential to fetch the providers
// linked to the email:
var email = error.email;
// The provider's credential:
var credential = error.credential;
// In case of auth/account-exists-with-different-credential error,
// you can fetch the providers using this:
if (error.code === 'auth/account-exists-with-different-credential') {
auth.fetchProvidersForEmail(email).then(function(providers) {
// The returned 'providers' is a list of the available providers
// linked to the email address. Please refer to the guide for a more
// complete explanation on how to recover from this error.
});
}
});

signInWithRedirect
signInWithRedirect(provider) returns firebase.Promisecontaining void

Authenticates a Firebase client using a full-page redirect ow. To handle the results and errors for this operation, refer
torebase.auth.Auth#getRedirectResult.

Error Codes

auth/auth-domain-cong-required

Thrown if authDomain conguration is not provided when calling rebase.initializeApp(). Check Firebase Console for instructions
on determining and passing that eld.

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.

https://firebase.google.com/docs/reference/js/firebase.auth.Auth 15/17
12/9/2017 Interface: Auth | Firebase

auth/unauthorized-domain

Thrown if the app domain is not authorized for OAuth operations for your Firebase project. Edit the list of authorized domains from
the Firebase console.

Parameter

provider

rebase.auth.AuthProvider
The provider to authenticate. The provider has to be an
OAuth provider. Non-OAuth providers
likerebase.auth.EmailAuthProviderwill throw an error.
Value must not be null.

Returns

non-null firebase.Promise containing void

signOut
signOut() returns firebase.Promise containing void

Signs out the current user.

Returns

non-null firebase.Promise containing void

useDeviceLanguage
useDeviceLanguage()

Sets the current language to the default device/browser preference.

verifyPasswordResetCode
verifyPasswordResetCode(code) returns firebase.Promisecontaining 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 verication code sent to the user.

https://firebase.google.com/docs/reference/js/firebase.auth.Auth 16/17
12/9/2017 Interface: Auth | Firebase

Returns

non-null firebase.Promise containing string

Except as otherwise noted, the content of this page is licensed under theCreative Commons Attribution 3.0 License, and code samples are licensed under theApache 2.0
License. For details, see ourSite Policies. Java is a registered trademark of Oracle and/or its afliates.

Last updated Agosto 17, 2017.

https://firebase.google.com/docs/reference/js/firebase.auth.Auth 17/17