@react-native-firebase/appinstalled and native config completed per Getting Started (Androidgoogle-services.json, iOSGoogleService-Info.plist, Expo config plugin, or React Native CLI setup). From v26, New Architecture is required for packages with a native bridge.- Install Auth:
npm install --save @react-native-firebase/authoryarn add @react-native-firebase/auth, then rebuild native apps (cd ios && pod installon iOS). - Enable the sign-in providers you use under Firebase Console → Authentication → Sign-in method.
Example Expo Router screen: https://github.com/invertase/react-native-firebase/blob/main/test-expo/app/auth/index.tsx (connects to the Auth emulator and has one control per function on this page). Related screens in the same folder cover social providers, phone, email link and multi-factor flows.
# Install & setup the app module
yarn add @react-native-firebase/app
# Install the authentication module
yarn add @react-native-firebase/auth
# If you're developing your app using iOS, run this command
cd ios/ && pod install{/* prettier-ignore */}
| Platforms | Android, iOS (native Firebase SDK) |
| New Architecture | Required from v26. See Migrating to v26. |
Platform notes: Several firebase-js-sdk web helpers throw on React Native (setPersistence, getRedirectResult, revokeAccessToken, useDeviceLanguage, linkWithPhoneNumber, reauthenticateWithPhoneNumber); see Web-only helpers that throw. initializeAuth accepts the firebase-js-sdk dependency argument but ignores it. React Native Firebase also exports RN-only helpers such as SDK_VERSION, setLanguageCode, useUserAccessGroup, getCustomAuthDomain, verifyPhoneNumber, and related phone-listener types. Each is explained in the section that uses it (phone helpers live on Phone Authentication). See Migrating to v26, Platform behavior differences.
Firebase Authentication provides backend services & easy-to-use SDKs to authenticate users to your app. It supports authentication using passwords, phone numbers, popular federated identity providers like Google, Facebook and Twitter, and more.
Firebase Authentication integrates tightly with other Firebase services, and it leverages industry standards like OAuth 2.0 and OpenID Connect, so it can be easily integrated with your custom backend.
Use connectAuthEmulator before any Auth calls when talking to the Local Emulator Suite (the Authentication emulator listens on port 9099 by default). Pass a full URL. On Android emulators, use 10.0.2.2 instead of localhost / 127.0.0.1 so the guest can reach the host machine.
import { Platform } from 'react-native';
import { connectAuthEmulator, getAuth } from '@react-native-firebase/auth';
const host = Platform.OS === 'android' ? '10.0.2.2' : '127.0.0.1';
connectAuthEmulator(getAuth(), `http://${host}:9099`);initializeAuth(app, deps?) exists for firebase-js-sdk parity. The optional deps argument (persistence, popup/redirect resolver, error map) is ignored because the native iOS and Android SDKs manage persistence. The call returns the same Auth instance as getAuth(app), so it configures nothing extra. Prefer getAuth() unless code shared with a web app already calls initializeAuth.
import { getApp } from '@react-native-firebase/app';
import { getAuth, initializeAuth } from '@react-native-firebase/auth';
const app = getApp();
const auth = initializeAuth(app);
console.log('Same Auth instance as getAuth:', auth === getAuth(app));In most scenarios using Authentication, you will want to know whether your users are signed-in or signed-out
of your application. The module provides a method called onAuthStateChanged which allows you to subscribe to the users
authentication state, and receive an event whenever that state changes.
It is important to remember the onAuthStateChanged listener is asynchronous and will trigger an initial state once
a connection with Firebase has been established. Therefore it is important to setup an "initializing" state which blocks
render of our main application whilst the connection is established:
import React, { useState, useEffect } from 'react';
import { View, Text } from 'react-native';
import { getAuth, onAuthStateChanged } from '@react-native-firebase/auth';
function App() {
// Set an initializing state whilst Firebase connects
const [initializing, setInitializing] = useState(true);
const [user, setUser] = useState(
/** @type {import('@react-native-firebase/auth').User | null} */ (null),
);
// Handle user state changes
function handleAuthStateChanged(nextUser) {
setUser(nextUser);
if (initializing) {
setInitializing(false);
}
}
useEffect(() => {
const subscriber = onAuthStateChanged(getAuth(), handleAuthStateChanged);
return subscriber; // unsubscribe on unmount
}, []);
if (initializing) return null;
if (!user) {
return (
<View>
<Text>Login</Text>
</View>
);
}
return (
<View>
<Text>Welcome {user.email}</Text>
</View>
);
}If the user returned within the handler is null we assume the user is signed-out, otherwise they are
signed-in and a User interface is returned.
The onAuthStateChanged method also returns an unsubscriber function which allows us to stop listening for events whenever
the hook is no longer in use.
AuthListenerCallback is the exported callback type for that listener ((user: User | null) => void). CallbackOrObserver is the exported union that also accepts an observer-shaped { next } object. firebase-js-sdk keeps those shapes inline on onAuthStateChanged / onIdTokenChanged rather than exporting the aliases.
import { getAuth, onAuthStateChanged } from '@react-native-firebase/auth';
/** @type {import('@react-native-firebase/auth').AuthListenerCallback} */
function handleUser(user) {
console.log('uid', user?.uid ?? null);
}
/** @type {import('@react-native-firebase/auth').CallbackOrObserver<import('@react-native-firebase/auth').AuthListenerCallback>} */
const observer = { next: handleUser };
const unsubscribeFn = onAuthStateChanged(getAuth(), handleUser);
const unsubscribeObserver = onAuthStateChanged(getAuth(), observer);
unsubscribeFn();
unsubscribeObserver();onIdTokenChanged fires when the signed-in user's ID token changes (refresh, sign-in, sign-out). Use the same AuthListenerCallback / CallbackOrObserver shapes as onAuthStateChanged.
import { getAuth, onIdTokenChanged } from '@react-native-firebase/auth';
const unsubscribe = onIdTokenChanged(getAuth(), user => {
console.log('ID token user:', user?.uid ?? null);
});
unsubscribe();beforeAuthStateChanged(auth, callback, onAbort?) registers a callback that runs, and is awaited, before onAuthStateChanged listeners are notified of a sign-in or sign-out. The callback receives the pending User or null. If the callback throws or rejects, onAbort runs and that state change is not delivered to onAuthStateChanged listeners. Throwing does not undo the sign-in or sign-out that already happened in the native SDK. The function returns an unsubscribe function. It only gates auth state events; onIdTokenChanged listeners are not affected.
import { beforeAuthStateChanged, getAuth } from '@react-native-firebase/auth';
const unsubscribe = beforeAuthStateChanged(
getAuth(),
async user => {
console.log('About to publish auth state for', user?.uid ?? null);
},
() => {
console.log('A beforeAuthStateChanged callback threw, listeners were not notified');
},
);
unsubscribe();On web based applications, the Firebase Web SDK takes advantage of features such as cookies and local storage to persist the users authenticated state across sessions. The native Firebase SDKs also provide this functionality using device native SDKs, ensuring that a users previous authentication state between app sessions is persisted.
The user is able to clear their state by deleting the apps data/cache from the device settings.
setPersistence always throws on React Native Firebase, so there is no persistence type to choose. See Web-only helpers that throw.
Some applications don't require authentication, which make it tricky to identify what users are doing throughout your app.
If connecting with external APIs, it is also useful to add an extra layer of security by ensuring the users request is
from the app. This can be achieved with the signInAnonymously method, which creates a new anonymous user which is persisted,
allowing you to integrate with other services such as Analytics by providing a user ID.
Ensure the "Anonymous" sign-in provider is enabled on the Firebase Console.
import { getAuth, signInAnonymously } from '@react-native-firebase/auth';
signInAnonymously(getAuth())
.then(() => {
console.log('User signed in anonymously');
})
.catch(error => {
if (error.code === 'auth/operation-not-allowed') {
console.log('Enable anonymous in your firebase console.');
}
console.error(error);
});Once successfully signed in, any onAuthStateChanged listeners will trigger an event
with the User details.
In case any errors occur, the module provides support for identifying what specifically went wrong by attaching a code to the error. For a full list of error codes available, view the Firebase documentation.
When an anonymous user later signs up, link email/password (or another provider credential) so they keep the same Firebase uid:
import { EmailAuthProvider, getAuth, linkWithCredential } from '@react-native-firebase/auth';
async function linkEmailPasswordToCurrentUser(email, password) {
const user = getAuth().currentUser;
if (!user) {
throw new Error('No user is signed in');
}
const credential = EmailAuthProvider.credential(email, password);
return linkWithCredential(user, credential);
}
await linkEmailPasswordToCurrentUser('jane.doe@example.com', 'SuperSecretPassword!');Email/password sign in is a common method for user sign in on applications. This requires the user to provide an email
address and secure password. Users can both register and sign in using a method called createUserWithEmailAndPassword
or sign in to an existing account with signInWithEmailAndPassword.
Ensure the "Email/Password" sign-in provider is enabled on the Firebase Console.
The createUserWithEmailAndPassword performs two operations; first creating the user if they do not already exist, and
then signing them in.
import { getAuth, createUserWithEmailAndPassword } from '@react-native-firebase/auth';
createUserWithEmailAndPassword(getAuth(), 'jane.doe@example.com', 'SuperSecretPassword!')
.then(() => {
console.log('User account created & signed in!');
})
.catch(error => {
if (error.code === 'auth/email-already-in-use') {
console.log('That email address is already in use!');
}
if (error.code === 'auth/invalid-email') {
console.log('That email address is invalid!');
}
console.error(error);
});Sign in an existing account:
import { getAuth, signInWithEmailAndPassword } from '@react-native-firebase/auth';
signInWithEmailAndPassword(getAuth(), 'jane.doe@example.com', 'SuperSecretPassword!')
.then(userCredential => {
console.log('Signed in:', userCredential.user.email);
})
.catch(error => {
console.error(error.code, error.message);
});Once successfully created and/or signed in, any onAuthStateChanged listeners will trigger an event
with the User details.
In case any errors occur, the module provides support for identifying what specifically went wrong by attaching a code to the error. For a full list of error codes available, view the Firebase documentation.
When the project has a password policy configured in the Firebase Console (Authentication → Settings → Password policy), call validatePassword on the client before sign-up:
import { getAuth, validatePassword } from '@react-native-firebase/auth';
async function checkPasswordMeetsPolicy(password) {
const status = await validatePassword(getAuth(), password);
if (!status.isValid) {
console.log('Password does not meet project policy', status);
}
return status;
}
await checkPasswordMeetsPolicy('SuperSecretPassword!');fetchSignInMethodsForEmail resolves with the sign-in method IDs (for example password or google.com) registered for an email address. Do not rely on it for identifier-first sign-in screens when email enumeration protection is enabled for the project. See Email enumeration protection.
import { fetchSignInMethodsForEmail, getAuth } from '@react-native-firebase/auth';
async function logSignInMethods(email) {
const methods = await fetchSignInMethodsForEmail(getAuth(), email);
console.log('Sign-in methods:', methods);
return methods;
}
await logSignInMethods('jane.doe@example.com');If your backend mints Firebase custom tokens (Admin SDK), exchange them with signInWithCustomToken:
import { getAuth, signInWithCustomToken } from '@react-native-firebase/auth';
async function signInWithBackendCustomToken(customToken) {
return signInWithCustomToken(getAuth(), customToken);
}
await signInWithBackendCustomToken('CUSTOM_TOKEN_FROM_YOUR_SERVER');Prefer an auth state observer for a stable current user. You can also read getAuth().currentUser (it may be null while Auth is still initializing).
import { getAuth } from '@react-native-firebase/auth';
function logCurrentUserProfile() {
const user = getAuth().currentUser;
if (!user) {
console.log('No user is signed in');
return;
}
console.log({
displayName: user.displayName,
email: user.email,
photoURL: user.photoURL,
emailVerified: user.emailVerified,
uid: user.uid,
});
user.providerData.forEach(profile => {
console.log(profile.providerId, profile.uid, profile.email);
});
}
logCurrentUserProfile();updateProfile accepts an UpdateProfile options object (displayName / photoURL). React Native Firebase exports that alias; firebase-js-sdk declares the shape inline on updateProfile.
import { getAuth, updateProfile } from '@react-native-firebase/auth';
async function updateSignedInUserProfile() {
const user = getAuth().currentUser;
if (!user) {
throw new Error('No user is signed in');
}
/** @type {import('@react-native-firebase/auth').UpdateProfile} */
const profile = {
displayName: 'Jane Q. User',
photoURL: 'https://example.com/jane-q-user/profile.jpg',
};
await updateProfile(user, profile);
}
await updateSignedInUserProfile();Some security-sensitive updates require a recent sign-in. See Re-authenticate.
import { getAuth, updateEmail, sendEmailVerification } from '@react-native-firebase/auth';
async function changeEmailAndSendVerification(newEmail) {
const user = getAuth().currentUser;
if (!user) {
throw new Error('No user is signed in');
}
await updateEmail(user, newEmail);
await sendEmailVerification(user);
}
await changeEmailAndSendVerification('user@example.com');sendEmailVerification(user, actionCodeSettings?) also accepts ActionCodeSettings to control the link in the email.
verifyBeforeUpdateEmail(user, newEmail, actionCodeSettings?) sends a verification email to newEmail. It does not change the account email on its own: the address changes once the user follows the link in that email, and reload(user) then refreshes the cached profile. Use it instead of updateEmail when the new address must be confirmed before it replaces the current one. It requires a signed-in user and may need a recent sign-in; see Re-authenticate. The optional third argument is the same ActionCodeSettings object used by sendEmailVerification.
import { getAuth, reload, verifyBeforeUpdateEmail } from '@react-native-firebase/auth';
async function requestEmailChange(newEmail) {
const user = getAuth().currentUser;
if (!user) {
throw new Error('No user is signed in');
}
await verifyBeforeUpdateEmail(user, newEmail);
}
async function refreshAfterUserFollowedLink() {
const user = getAuth().currentUser;
if (!user) {
throw new Error('No user is signed in');
}
await reload(user);
// Read currentUser again: reload replaces auth.currentUser with a new User object.
console.log('Email after reload:', getAuth().currentUser?.email);
}
await requestEmailChange('new.address@example.com');
await refreshAfterUserFollowedLink();import { getAuth, updatePassword, sendPasswordResetEmail } from '@react-native-firebase/auth';
async function changePassword(newPassword) {
const user = getAuth().currentUser;
if (!user) {
throw new Error('No user is signed in');
}
await updatePassword(user, newPassword);
}
async function sendResetEmail(email) {
await sendPasswordResetEmail(getAuth(), email);
}
await changePassword('AnotherSecurePassword!');
await sendResetEmail('jane.doe@example.com');sendPasswordResetEmail(auth, email, actionCodeSettings?) also accepts ActionCodeSettings.
sendEmailVerification, sendPasswordResetEmail, and verifyBeforeUpdateEmail accept an optional ActionCodeSettings object that controls where the link in the email leads. Without it, Firebase sends the default link. The email-link sign-in helper sendSignInLinkToEmail takes the same object but requires it; see Email Link Authentication for the App Links / Universal Links setup that handleCodeInApp depends on.
{/* prettier-ignore */}
| Field | Type | Notes |
|---|---|---|
url | string (required) | Continue URL. Its domain must be listed under Authentication → Settings → Authorized domains in the Firebase Console. |
handleCodeInApp | boolean | Set true to have the link opened in your app instead of a web page first. |
iOS.bundleId | string | Bundle ID of the iOS app that should handle the link. Required when iOS is set. |
android.packageName | string | Package name of the Android app that should handle the link. Required when android is set. |
android.installApp | boolean | Offer to install the Android app when it is missing. |
android.minimumVersion | string | Minimum Android app version that can handle the link. |
linkDomain | string | Custom Firebase Hosting link domain. Omit it unless the project uses a custom Hosting link domain. |
dynamicLinkDomain | string | Declared on the type but not forwarded by the iOS or Android bridge. Omit it. |
sendEmailVerification and verifyBeforeUpdateEmail validate the object before calling the native SDK and throw an Error when url is not a string, when iOS.bundleId or android.packageName is not a string while the parent object is set, when handleCodeInApp or android.installApp is not a boolean, or when android.minimumVersion or linkDomain is not a string.
import {
getAuth,
sendEmailVerification,
sendPasswordResetEmail,
verifyBeforeUpdateEmail,
} from '@react-native-firebase/auth';
/** @type {import('@react-native-firebase/auth').ActionCodeSettings} */
const actionCodeSettings = {
url: 'https://YOUR_PROJECT_ID.firebaseapp.com/finishAction',
handleCodeInApp: true,
iOS: {
bundleId: 'com.yourcompany.yourapp',
},
android: {
packageName: 'com.yourcompany.yourapp',
installApp: true,
minimumVersion: '12',
},
};
async function sendVerificationWithSettings() {
const user = getAuth().currentUser;
if (!user) {
throw new Error('No user is signed in');
}
await sendEmailVerification(user, actionCodeSettings);
}
async function sendPasswordResetWithSettings(email) {
await sendPasswordResetEmail(getAuth(), email, actionCodeSettings);
}
async function requestEmailChangeWithSettings(newEmail) {
const user = getAuth().currentUser;
if (!user) {
throw new Error('No user is signed in');
}
await verifyBeforeUpdateEmail(user, newEmail, actionCodeSettings);
}
await sendVerificationWithSettings();
await sendPasswordResetWithSettings('jane.doe@example.com');
await requestEmailChangeWithSettings('new.address@example.com');import { getAuth, reload, deleteUser, unlink } from '@react-native-firebase/auth';
async function reloadCurrentUser() {
const user = getAuth().currentUser;
if (!user) {
throw new Error('No user is signed in');
}
await reload(user);
}
async function deleteCurrentUser() {
const user = getAuth().currentUser;
if (!user) {
throw new Error('No user is signed in');
}
await deleteUser(user);
}
async function unlinkProvider(providerId) {
const user = getAuth().currentUser;
if (!user) {
throw new Error('No user is signed in');
}
return unlink(user, providerId);
}
await reloadCurrentUser();
await unlinkProvider('google.com');
await deleteCurrentUser();import {
EmailAuthProvider,
getAuth,
reauthenticateWithCredential,
} from '@react-native-firebase/auth';
async function reauthenticateWithEmailPassword(email, password) {
const user = getAuth().currentUser;
if (!user) {
throw new Error('No user is signed in');
}
const credential = EmailAuthProvider.credential(email, password);
return reauthenticateWithCredential(user, credential);
}
await reauthenticateWithEmailPassword('jane.doe@example.com', 'SuperSecretPassword!');For OAuth providers that use a native sign-in flow, reauthenticateWithPopup and reauthenticateWithRedirect re-authenticate with a provider instead of a credential; see Re-authenticate with a provider.
updateCurrentUser(auth, user) returns a promise. Passing null signs out, the same as signOut(auth). Passing a User only works with a user object created by the same Auth instance (the same Firebase app); any other value rejects with an error. It cannot sign in an account that was not already signed in through that Auth instance; use a sign-in method to switch accounts.
import { getAuth, updateCurrentUser } from '@react-native-firebase/auth';
async function reapplyCurrentUser() {
const auth = getAuth();
const user = auth.currentUser;
if (!user) {
throw new Error('No user is signed in');
}
await updateCurrentUser(auth, user);
}
async function signOutWithUpdateCurrentUser() {
await updateCurrentUser(getAuth(), null);
}
await reapplyCurrentUser();
await signOutWithUpdateCurrentUser();setLanguageCode sets auth.languageCode for localized email templates and related Auth UI strings. It is an RN Firebase modular helper; firebase-js-sdk apps typically assign auth.languageCode or call useDeviceLanguage() (the latter throws on React Native).
import { getAuth, setLanguageCode } from '@react-native-firebase/auth';
await setLanguageCode(getAuth(), 'it');useUserAccessGroup shares Auth credentials across apps in an iOS App Group. iOS native only; calling it on other platforms can throw.
import { Platform } from 'react-native';
import { getAuth, useUserAccessGroup } from '@react-native-firebase/auth';
async function shareAuthAcrossIosApps(appGroup) {
if (Platform.OS !== 'ios') {
throw new Error('useUserAccessGroup is iOS only');
}
await useUserAccessGroup(getAuth(), appGroup);
}
await shareAuthAcrossIosApps('group.com.example.shared');getCustomAuthDomain returns the native custom auth domain configured for the Firebase app on iOS/Android. On Web the call rejects with auth/unsupported.
import { getAuth, getCustomAuthDomain } from '@react-native-firebase/auth';
async function logCustomAuthDomain() {
const domain = await getCustomAuthDomain(getAuth());
console.log('Custom auth domain:', domain);
}
await logCustomAuthDomain();After a credential-based sign-in, getAdditionalUserInfo returns profile metadata. On React Native the result is typed as AdditionalUserInfoNative: firebase-js-sdk AdditionalUserInfo core fields plus an index signature for extra native bridge keys.
import {
getAuth,
getAdditionalUserInfo,
signInWithEmailAndPassword,
} from '@react-native-firebase/auth';
async function signInAndLogAdditionalInfo(email, password) {
const userCredential = await signInWithEmailAndPassword(getAuth(), email, password);
// Typed as AdditionalUserInfoNative on React Native (core fields + native bridge keys).
const info = getAdditionalUserInfo(userCredential);
console.log(info?.isNewUser, info?.providerId, info?.profile);
return info;
}
await signInAndLogAdditionalInfo('jane.doe@example.com', 'SuperSecretPassword!');The package exports string constants you can compare against instead of repeating literals:
ProviderId:FACEBOOK,GITHUB,GOOGLE,PASSWORD,PHONE,TWITTERSignInMethod:EMAIL_LINK,EMAIL_PASSWORD,FACEBOOK,GITHUB,GOOGLE,PHONE,TWITTEROperationType:LINK,REAUTHENTICATE,SIGN_INFactorId:PHONE,TOTPActionCodeOperation:EMAIL_SIGNIN,PASSWORD_RESET,RECOVER_EMAIL,REVERT_SECOND_FACTOR_ADDITION,VERIFY_AND_CHANGE_EMAIL,VERIFY_EMAIL
import {
ActionCodeOperation,
FactorId,
OperationType,
ProviderId,
SignInMethod,
fetchSignInMethodsForEmail,
getAuth,
parseActionCodeURL,
signInWithEmailAndPassword,
} from '@react-native-firebase/auth';
async function describeSignIn(email, password) {
const userCredential = await signInWithEmailAndPassword(getAuth(), email, password);
console.log('Sign-in operation:', userCredential.operationType === OperationType.SIGN_IN);
console.log(
'Has password provider:',
userCredential.user.providerData.some(info => info.providerId === ProviderId.PASSWORD),
);
const methods = await fetchSignInMethodsForEmail(getAuth(), email);
console.log('Email link enabled for this address:', methods.includes(SignInMethod.EMAIL_LINK));
}
function isEmailChangeLink(link) {
const parsed = parseActionCodeURL(link);
return parsed?.operation === ActionCodeOperation.VERIFY_AND_CHANGE_EMAIL;
}
function isTotpHint(hint) {
return hint.factorId === FactorId.TOTP;
}
await describeSignIn('jane.doe@example.com', 'SuperSecretPassword!');
console.log(
isEmailChangeLink(
'https://example.com/usermgmt?mode=verifyAndChangeEmail&oobCode=ABC123&apiKey=YOUR_API_KEY',
),
);
console.log(isTotpHint({ factorId: 'totp' }));Native bridge failures use NativeFirebaseAuthError, which extends the shared React Native Firebase error shape with userInfo.authCredential and userInfo.resolver (for multi-factor). Prefer checking error.code strings from the Auth error reference.
import { getAuth, signInWithEmailAndPassword } from '@react-native-firebase/auth';
async function signInCatchingNativeAuthError(email, password) {
try {
await signInWithEmailAndPassword(getAuth(), email, password);
} catch (error) {
/** @type {import('@react-native-firebase/auth').NativeFirebaseAuthError} */
const authError = error;
console.log(authError.code, authError.userInfo?.authCredential);
}
}
await signInCatchingNativeAuthError('jane.doe@example.com', 'wrong-password');Custom email action handlers (password reset, email verification, recover email) parse mode / oobCode from the link, then call the modular helpers. parseActionCodeURL extracts those fields from a full link string when you handle the URL in-app. It returns an ActionCodeURL with apiKey, code, continueUrl, languageCode, operation (an ActionCodeOperation value) and tenantId, or null when the link is missing apiKey, oobCode, or a supported mode.
import {
applyActionCode,
checkActionCode,
confirmPasswordReset,
getAuth,
parseActionCodeURL,
verifyPasswordResetCode,
} from '@react-native-firebase/auth';
async function handlePasswordResetFromLink(link, newPassword) {
const parsed = parseActionCodeURL(link);
if (!parsed?.code) {
throw new Error('Not an Auth action link');
}
const email = await verifyPasswordResetCode(getAuth(), parsed.code);
await confirmPasswordReset(getAuth(), parsed.code, newPassword);
return email;
}
async function handleVerifyOrRecoverEmail(oobCode) {
const info = await checkActionCode(getAuth(), oobCode);
await applyActionCode(getAuth(), oobCode);
return info;
}
await handlePasswordResetFromLink(
'https://example.com/usermgmt?mode=resetPassword&oobCode=ABC123&apiKey=YOUR_API_KEY',
'AnotherSecurePassword!',
);
await handleVerifyOrRecoverEmail('ABC123');The user's token should be used for authentication with your backend systems. The token is fetched with the getIdToken method. As mentioned in the Firebase documentation, the uid should not be used for authentication.
import { getAuth, getIdToken, getIdTokenResult } from '@react-native-firebase/auth';
async function fetchBackendWithIdToken() {
const user = getAuth().currentUser;
if (!user) {
throw new Error('No user is signed in');
}
const idToken = await getIdToken(user);
const tokenResult = await getIdTokenResult(user);
console.log('claims', tokenResult.claims);
const response = await fetch('https://example.com/api/protected', {
headers: {
Authorization: `Bearer ${idToken}`,
},
});
return response.json();
}
await fetchBackendWithIdToken();If you'd like to sign the user out of their authentication state, call the signOut method:
import { getAuth, signOut } from '@react-native-firebase/auth';
signOut(getAuth()).then(() => console.log('User signed out!'));Once successfully signed out, any onAuthStateChanged listeners will trigger an event
with the user parameter being a null value.
Additionally, calling revokeAccess() on your Google sign-in library forgets the user on the device (for example GoogleOneTapSignIn.revokeAccess() from react-native-nitro-google-signin, or GoogleSignin.revokeAccess() from @react-native-google-signin/google-signin). The next sign-in will show the account picker again. Without it, the last account may be reused automatically.
These firebase-js-sdk helpers are exported for API parity. Each one throws an Error synchronously on React Native Firebase instead of returning a rejected promise, so wrap the call in try / catch if shared code may reach it.
{/* prettier-ignore */}
| Function | Instead |
|---|---|
setPersistence | Nothing to configure; the native SDKs persist the signed-in user. |
getRedirectResult | signInWithRedirect resolves with the UserCredential directly. |
revokeAccessToken | revokeToken for Sign in with Apple; see Apple. |
useDeviceLanguage | setLanguageCode; see Language code. |
linkWithPhoneNumber | verifyPhoneNumber, PhoneAuthProvider.credential, then linkWithCredential; see Phone Authentication. |
reauthenticateWithPhoneNumber | verifyPhoneNumber, PhoneAuthProvider.credential, then reauthenticateWithCredential; see Phone Authentication. |
Firebase also supports authenticating with external providers. To learn more, view the documentation for your authentication method:
- Apple Sign-In.
- Facebook Sign-In.
- Twitter Sign-In.
- Google Sign-In.
- GitHub Sign-In.
- Microsoft Sign-In.
- Phone Number Sign-In.
- Email Link Sign-In (passwordless App Links / Universal Links).
- OpenID Connect.
- Multi-factor Auth.
SDK_VERSION is the React Native Firebase Auth package version string exported from @react-native-firebase/auth. The firebase-js-sdk does not export SDK_VERSION from @firebase/auth.
import { SDK_VERSION } from '@react-native-firebase/auth';
console.log('Auth package version:', SDK_VERSION);
Core / App