auth
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
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;
Methods
- applyActionCode
- checkActionCode
- confirmPasswordReset
- createUserWithEmailAndPassword
- fetchSignInMethodsForEmail
- generateSecret
- getMultiFactorResolver
- isSignInWithEmailLink
- multiFactor
- onAuthStateChanged
- onIdTokenChanged
- onUserChanged
- resolveTotpMultiFactorSignIn
- revokeToken
- sendPasswordResetEmail
- sendSignInLinkToEmail
- setLanguageCode
- setTenantId
- signInAnonymously
- signInWithCredential
- signInWithCustomToken
- signInWithEmailAndPassword
- signInWithEmailLink
- signInWithPhoneNumber
- signInWithPopup
- signInWithProvider
- signInWithRedirect
- signOut
- useEmulator
- useUserAccessGroup
- verifyPasswordResetCode
- verifyPhoneNumber
- verifyPhoneNumberForMultiFactor
- verifyPhoneNumberWithMultiFactorInfo
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[]>;
generateSecret
</>generateSecret(session: MultiFactorSession, openInApp?: undefined | false | true): 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;
resolveTotpMultiFactorSignIn
</>resolveTotpMultiFactorSignIn(session: MultiFactorSession, verificationId: string, verificationCode: string): Promise<UserCredential>;
revokeToken
</>Revokes a user's Sign in with Apple token.
revokeToken(authorizationCode: string): Promise<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>;
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
</>Signs the user in with a specified provider. This is a web-compatible API along with signInWithRedirect. They both share the same call to the underlying native SDK signInWithProvider method.
signInWithPopup(provider: AuthProvider): Promise<UserCredential>;
signInWithProvider
</>Signs the user in with a federated OAuth provider supported by Firebase (Microsoft, Yahoo).
signInWithProvider(provider: AuthProvider): Promise<UserCredential>;
signInWithRedirect
</>Signs the user in with a specified provider. This is a web-compatible API along with signInWithPopup. They both share the same call to the underlying native SDK signInWithProvider method.
signInWithRedirect(provider: AuthProvider): Promise<UserCredential>;
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;
OIDCAuthProvider
</>Custom Open ID connect auth provider implementation.
auth.OIDCAuthProvider: OIDCProvider;
PhoneMultiFactorGenerator
</>A PhoneMultiFactorGenerator interface.
auth.PhoneMultiFactorGenerator: PhoneMultiFactorGenerator;
getMultiFactorResolver
</>auth.getMultiFactorResolver: getMultiFactorResolver;