Jump to top

auth

interface

The Firebase Authentication service is available for the default app or a given app.

Example 1

Get the auth instance for the default app:

const authForDefaultApp = firebase.auth();
Example 2

Get the auth instance for a secondary app:

const otherApp = firebase.app('otherApp');
const authForOtherApp = firebase.auth(otherApp);

TODO @salakar missing updateCurrentUser

Properties

app

</>

The current FirebaseApp instance for this Firebase service.

currentUser

</>

Returns the currently signed-in user (or null if no user signed in). See the User interface documentation for detailed usage.

currentUser: User | null;

languageCode

</>

Returns the current language code.

languageCode: string;

settings

</>

Returns the current AuthSettings.

settings: AuthSettings;

tenantId

</>

Returns the current tenant Id or null if it has never been set

tenantId: string | null;

Methods

applyActionCode

</>

Applies a verification code sent to the user by email or other out-of-band mechanism.

applyActionCode(code: string): Promise<void>;

checkActionCode

</>

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

checkActionCode(code: string): Promise<ActionCodeInfo>;

confirmPasswordReset

</>

Completes the password reset process with the confirmation code and new password, via auth#sendPasswordResetEmail.

confirmPasswordReset(code: string, newPassword: string): Promise<void>;

createUserWithEmailAndPassword

</>

Creates a new user with an email and password.

createUserWithEmailAndPassword(email: string, password: string): Promise<UserCredential>;

fetchSignInMethodsForEmail

</>

Returns a list of authentication methods that can be used to sign in a given user (identified by its main email address).

fetchSignInMethodsForEmail(email: string): Promise<string[]>;

getMultiFactorResolver

</>

Provides a MultiFactorResolver suitable for completion of a multi-factor flow.

getMultiFactorResolver(error: MultiFactorError): MultiFactorResolver;

isSignInWithEmailLink

</>

Returns whether the user signed in with a given email link.

isSignInWithEmailLink(emailLink: string): boolean;

multiFactor

</>

The MultiFactorUser corresponding to the user.

multiFactor(user: User): MultiFactorUser;

onAuthStateChanged

</>

Listen for changes in the users auth state (logging in and out). This method returns a unsubscribe function to stop listening to events. Always ensure you unsubscribe from the listener when no longer needed to prevent updates to components no longer in use.

onAuthStateChanged(listener: CallbackOrObserver<AuthListenerCallback>): () => void;

onIdTokenChanged

</>

Listen for changes in ID token. ID token can be verified (if desired) using the admin SDK or a 3rd party JWT library This method returns a unsubscribe function to stop listening to events. Always ensure you unsubscribe from the listener when no longer needed to prevent updates to components no longer in use.

onIdTokenChanged(listener: CallbackOrObserver<AuthListenerCallback>): () => void;

onUserChanged

</>

Adds a listener to observe changes to the User object. This is a superset of everything from auth#onAuthStateChanged, auth#onIdTokenChanged and user changes. The goal of this method is to provide easier listening to all user changes, such as when credentials are linked and unlinked, without manually having to call User#reload.

onUserChanged(listener: CallbackOrObserver<AuthListenerCallback>): () => void;

sendPasswordResetEmail

</>

Sends a password reset email to the given email address. Unlike the web SDK, the email will contain a password reset link rather than a code.

sendPasswordResetEmail(email: string, actionCodeSettings?: ActionCodeSettings): Promise<void>;

sendSignInLinkToEmail

</>

Sends a sign in link to the user.

sendSignInLinkToEmail(email: string, actionCodeSettings?: ActionCodeSettings): Promise<void>;

setLanguageCode

</>

Sets the language code.

setLanguageCode(languageCode: string | null): Promise<void>;

setTenantId

</>

Sets the tenant id.

setTenantId(tenantId: string): Promise<void>;

signInAnonymously

</>

Sign in a user anonymously. If the user has already signed in, that user will be returned.

signInAnonymously(): Promise<UserCredential>;

signInWithCredential

</>

Signs the user in with a generated credential.

signInWithCredential(credential: AuthCredential): Promise<UserCredential>;

signInWithCustomToken

</>

Signs a user in with a custom token.

signInWithCustomToken(customToken: string): Promise<UserCredential>;

signInWithEmailAndPassword

</>

Signs a user in with an email and password.

signInWithEmailAndPassword(email: string, password: string): Promise<UserCredential>;

signInWithEmailLink

</>

Signs the user in with an email link.

signInWithEmailLink(email: string, emailLink: string): Promise<UserCredential>;

signInWithPhoneNumber

</>

Signs in the user using their phone number.

signInWithPhoneNumber(phoneNumber: string, forceResend?: undefined | false | true): Promise<ConfirmationResult>;

signInWithPopup

</>
signInWithPopup(provider: AuthProvider): Promise<UserCredential>;

signInWithRedirect

</>
signInWithRedirect(provider: AuthProvider): Promise<UserCredential>;

signOut

</>

Signs the user out.

signOut(): Promise<void>;

useEmulator

</>

Modify this Auth instance to communicate with the Firebase Auth emulator. This must be called synchronously immediately following the first call to firebase.auth(). Do not use with production credentials as emulator traffic is not encrypted.

useEmulator(url: string): void;

useUserAccessGroup

</>

Switch userAccessGroup and current user to the given accessGroup and the user stored in it. Sign in a user with any sign in method, and the same current user is available in all apps in the access group.

useUserAccessGroup(userAccessGroup: string): Promise<null>;

verifyPasswordResetCode

</>

Checks a password reset code sent to the user by email or other out-of-band mechanism. TODO salakar: confirm return behavior (Returns the user's email address if valid.)

verifyPasswordResetCode(code: string): Promise<string>;

verifyPhoneNumber

</>

Returns a PhoneAuthListener to listen to phone verification events, on the final completion event a PhoneAuthCredential can be generated for authentication purposes.

verifyPhoneNumber(phoneNumber: string, autoVerifyTimeoutOrForceResend?: number | boolean, forceResend?: undefined | false | true): PhoneAuthListener;

verifyPhoneNumberForMultiFactor

</>

Send an SMS to the user for verification of second factor

verifyPhoneNumberForMultiFactor(phoneInfoOptions: PhoneMultiFactorEnrollInfoOptions): Promise<string>;

verifyPhoneNumberWithMultiFactorInfo

</>

Obtain a verification id to complete the multi-factor sign-in flow.

verifyPhoneNumberWithMultiFactorInfo(hint: MultiFactorInfo, session: MultiFactorSession): Promise<string>;

Statics

AppleAuthProvider

</>

Apple auth provider implementation. Currently this is iOS only.

auth.AppleAuthProvider: AuthProvider;

EmailAuthProvider

</>

Email and password auth provider implementation.

auth.EmailAuthProvider: EmailAuthProvider;

FacebookAuthProvider

</>

Facebook auth provider implementation.

auth.FacebookAuthProvider: AuthProvider;

GithubAuthProvider

</>

Github auth provider implementation.

auth.GithubAuthProvider: AuthProvider;

GoogleAuthProvider

</>

Google auth provider implementation.

auth.GoogleAuthProvider: AuthProvider;

OAuthProvider

</>

Custom OAuth auth provider implementation.

auth.OAuthProvider: OAuthProvider;

OIDCAuthProvider

</>

Custom Open ID connect auth provider implementation.

auth.OIDCAuthProvider: OIDCProvider;

PhoneAuthProvider

</>

Phone auth provider implementation.

auth.PhoneAuthProvider: AuthProvider;

PhoneAuthState

</>

A PhoneAuthState interface.

auth.PhoneAuthState: PhoneAuthState;

PhoneMultiFactorGenerator

</>

A PhoneMultiFactorGenerator interface.

auth.PhoneMultiFactorGenerator: PhoneMultiFactorGenerator;

TwitterAuthProvider

</>

Twitter auth provider implementation.

auth.TwitterAuthProvider: AuthProvider;

getMultiFactorResolver

</>
auth.getMultiFactorResolver: getMultiFactorResolver;