Gets the config used to initialize this auth instance. This is to match Firebase JS SDK behavior. It returns an empty map as the config is not available in the native SDK.
Checks a verification code sent to the user by email or other out-of-band mechanism.
const actionCodeInfo = await firebase.auth().checkActionCode('ABCD');
console.log('Action code operation: ', actionCodeInfo.operation);
A verification code sent to the user.
Completes the password reset process with the confirmation code and new password, via sendPasswordResetEmail.
await firebase.auth().confirmPasswordReset('ABCD', '1234567');
The code from the password reset email.
The new password.
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.
Creates a new user with an email and password.
This method also signs the user in once the account has been created.
const userCredential = await firebase.auth().createUserWithEmailAndPassword('[email protected]', '123456');
The users email address.
The users password.
Returns a list of authentication methods that can be used to sign in a given user (identified by its main email address).
⚠️ Note: If "Email Enumeration Protection" is enabled in your Firebase Authentication settings (which is the default), this method may return an empty array even if the email is registered, especially when called from an unauthenticated context.
This is a security measure to prevent leaking account existence via email enumeration attacks. Do not use the result of this method to directly inform the user whether an email is registered.
const methods = await firebase.auth().fetchSignInMethodsForEmail('[email protected]');
if (methods.length > 0) {
// Likely a registered user — offer sign-in
} else {
// Could be unregistered OR email enumeration protection is active — offer registration
}
The user's email address.
Returns the custom auth domain for the auth instance.
Provides a MultiFactorResolver suitable for completion of a multi-factor flow.
Checks if an incoming link is a sign-in with email link suitable for signInWithEmailLink.
Note that android and other platforms require apiKey link parameter for signInWithEmailLink
const valid = await firebase.auth().isSignInWithEmailLink(link);
The email link to verify prior to using signInWithEmailLink
The MultiFactorUser corresponding to the user.
This is used to access all multi-factor properties and operations related to the user.
The user.
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.
const unsubscribe = firebase.auth().onAuthStateChanged((user) => {
if (user) {
// Signed in
} else {
// Signed out
}
});
// Unsubscribe from further state changes
unsubscribe();
A listener function which triggers when auth state changed (for example signing out).
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.
const unsubscribe = firebase.auth().onIdTokenChanged((user) => {
if (user) {
// User is signed in or token was refreshed.
}
});
// Unsubscribe from further state changes
unsubscribe();
A listener function which triggers when the users ID token changes.
Adds a listener to observe changes to the User object. This is a superset of everything from onAuthStateChanged, 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.
const unsubscribe = firebase.auth().onUserChanged((user) => {
if (user) {
// User is signed in or token was refreshed.
}
});
// Unsubscribe from further state changes
unsubscribe();
This is an experimental feature and is only part of React Native Firebase.
A listener function which triggers when the users data changes.
Revokes a user's Sign in with Apple token.
// Generate an Apple ID authorizationCode for the currently logged in user (ie, with @invertase/react-native-apple-authentication)
const { authorizationCode } = await appleAuth.performRequest({ requestedOperation: appleAuth.Operation.REFRESH });
// Revoke the token
await firebase.auth().revokeToken(authorizationCode);
A generated authorization code from Sign in with Apple.
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.
await firebase.auth().sendPasswordResetEmail('[email protected]');
The users email address.
OptionalactionCodeSettings: ActionCodeSettingsAdditional settings to be set before sending the reset email.
Sends a sign in link to the user.
await firebase.auth().sendSignInLinkToEmail('[email protected]');
The users email address.
OptionalactionCodeSettings: ActionCodeSettingsThe action code settings. The action code settings which provides Firebase with instructions on how to construct the email link. This includes the sign in completion URL or the deep link for mobile redirects, the mobile apps to use when the sign-in link is opened on an Android or iOS device. Mobile app redirects will only be applicable if the developer configures and accepts the Firebase Dynamic Links terms of condition. The Android package name and iOS bundle ID will be respected only if they are configured in the same Firebase Auth project used.
Sign in a user anonymously. If the user has already signed in, that user will be returned.
const userCredential = await firebase.auth().signInAnonymously();
Signs the user in with a generated credential.
// Generate a Firebase credential
const credential = firebase.auth.FacebookAuthProvider.credential('access token from Facebook');
// Sign the user in with the credential
const userCredential = await firebase.auth().signInWithCredential(credential);
A generated AuthCredential, for example from social auth.
auth/account-exists-with-different-credential Thrown if there already exists an account with the email address asserted by the credential.
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-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.
Signs a user in with a custom token.
// Create a custom token via the Firebase Admin SDK.
const token = await firebase.auth().createCustomToken(uid, customClaims);
...
// Use the token on the device to sign in.
const userCredential = await firebase.auth().signInWithCustomToken(token);
A custom token generated from the Firebase Admin SDK.
Signs a user in with an email and password.
⚠️ Note:
If "Email Enumeration Protection" is enabled in your Firebase Authentication settings (enabled by default),
Firebase may return a generic auth/invalid-login-credentials error instead of more specific ones like
auth/user-not-found or auth/wrong-password. This behavior is intended to prevent leaking information
about whether an account with the given email exists.
To receive detailed error codes, you must disable "Email Enumeration Protection", which may increase security risks if not properly handled on the frontend.
const userCredential = await firebase.auth().signInWithEmailAndPassword('[email protected]', '123456');
The user's email address.
The user's password.
Signs the user in with an email link.
const userCredential = await firebase.auth().signInWithEmailLink('[email protected]', link);
The users email to sign in with.
An email link.
Signs in the user using their phone number.
// Force a new message to be sent
const result = await firebase.auth().signInWithPhoneNumber('#4423456789', true);
The devices phone number.
OptionalforceResend: booleanForces a new message to be sent if it was already recently sent.
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.
// create a new OAuthProvider
const provider = firebase.auth.OAuthProvider('microsoft.com');
// Sign the user in with the provider
const userCredential = await firebase.auth().signInWithPopup(provider);
An AuthProvider configured for your desired provider, e.g. "microsoft.com"
auth/account-exists-with-different-credential Thrown if there already exists an account with the email address asserted by the credential.
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-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.
Signs the user in with a federated OAuth provider supported by Firebase (Microsoft, Yahoo).
From Firebase Docs: Unlike other OAuth providers supported by Firebase such as Google, Facebook, and Twitter, where sign-in can directly be achieved with OAuth access token based credentials, Firebase Auth does not support the same capability for providers such as Microsoft due to the inability of the Firebase Auth server to verify the audience of Microsoft OAuth access tokens.
// Generate an OAuth instance
const provider = new firebase.auth.OAuthProvider('microsoft.com');
// Optionally add scopes to the OAuth instance
provider.addScope('mail.read');
// Optionally add custom parameters to the OAuth instance
provider.setCustomParameters({
prompt: 'consent',
});
// Sign in using the OAuth provider
const userCredential = await firebase.auth().signInWithProvider(provider);
A generated AuthProvider, for example from social auth.
auth/account-exists-with-different-credential Thrown if there already exists an account with the email address asserted by the credential.
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-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.
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.
// create a new OAuthProvider
const provider = firebase.auth.OAuthProvider('microsoft.com');
// Sign the user in with the provider
const userCredential = await firebase.auth().signInWithRedirect(provider);
An AuthProvider configured for your desired provider, e.g. "microsoft.com"
auth/account-exists-with-different-credential Thrown if there already exists an account with the email address asserted by the credential.
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-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.
Signs the user out.
Triggers the onAuthStateChanged listener.
await firebase.auth().signOut();
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.
Note: on android, hosts 'localhost' and '127.0.0.1' are automatically remapped to '10.0.2.2' (the "host" computer IP address for android emulators) to make the standard development experience easy. If you want to use the emulator on a real android device, you will need to specify the actual host computer IP address.
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.
Set the useAccessGroup argument to null to stop sharing the auth state (default behaviour), the user state will no longer be
available to any other apps.
A string of the keychain id i.e. "TEAMID.com.example.group1"
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.)
const verifiedEmail = await firebase.auth().verifyPasswordResetCode('ABCD');
A password reset code.
The user's email address if valid
Returns a PhoneAuthListener to listen to phone verification events, on the final completion event a PhoneAuthCredential can be generated for authentication purposes.
firebase.auth().verifyPhoneNumber('+4423456789', )
.on('state_changed', (phoneAuthSnapshot) => {
console.log('Snapshot state: ', phoneAuthSnapshot.state);
});
The phone number identifier supplied by the user. Its format is normalized on the server, so it can be in any format here. (e.g. +16505550101).
OptionalautoVerifyTimeoutOrForceResend: number | booleanIf a number, sets in seconds how to to wait until auto verification times out. If boolean, sets the forceResend parameter.
OptionalforceResend: booleanIf true, resend the verification message even if it was recently sent.
Send an SMS to the user for verification of second factor
the phone number and session to use during enrollment
Obtain a verification id to complete the multi-factor sign-in flow.
The current FirebaseApp instance for this Firebase service.
Returns the currently signed-in user (or null if no user signed in). See the User interface documentation for detailed usage.
const user = firebase.auth().currentUser;
It is recommended to use onAuthStateChanged to track whether the user is currently signed in.
Returns the current AuthSettings.
The Firebase Authentication service is available for the default app or a given app.
Example 1
Get the auth instance for the default app:
Example 2
Get the auth instance for a secondary app:
TODO
Salakar
missing updateCurrentUser