The 'network request failed' error in Firebase Auth occurs when the app cannot reach Firebase's authentication servers. Common causes include CORS misconfigurations, overly restrictive API key settings, firewall or proxy blocks, missing internet permissions on mobile platforms, and emulator connectivity issues. This guide walks through each cause with specific diagnostic steps and fixes to restore authentication connectivity.
Resolving 'Network Request Failed' Errors in Firebase Authentication
When Firebase Auth cannot reach Google's identity servers, it throws a 'network request failed' error. This tutorial systematically diagnoses and fixes every common cause, from browser CORS issues and corporate firewalls to missing Android manifest permissions and emulator configuration problems. Each cause includes the specific symptoms to look for and the targeted fix.
Prerequisites
- A Firebase project with Authentication configured
- The firebase npm package installed (v9 or later)
- Access to browser developer tools or mobile debugging tools
- An active internet connection (for ruling out connectivity issues)
Step-by-step guide
Check basic internet connectivity
Check basic internet connectivity
Before diving into Firebase-specific debugging, confirm your device can reach Google's servers. Open a browser tab and navigate to https://identitytoolkit.googleapis.com. If this URL is unreachable, the issue is network-level (firewall, proxy, VPN, or no internet). On mobile, toggle airplane mode off and verify cellular or Wi-Fi is connected.
1// Quick connectivity test in browser console:2fetch('https://identitytoolkit.googleapis.com')3 .then(res => console.log('Reachable, status:', res.status))4 .catch(err => console.error('Unreachable:', err.message))56// Expected: status 404 (endpoint exists but needs params)7// If error: network is blocking the requestExpected result: The fetch succeeds with a 404 status code, confirming the server is reachable.
Fix API key restrictions blocking auth requests
Fix API key restrictions blocking auth requests
If you restricted your Firebase API key in the Google Cloud Console, it may block auth-related APIs. Go to Google Cloud Console > APIs & Services > Credentials, find your API key, and check the restrictions. Firebase Auth requires the Identity Toolkit API and Token Service API. If you set HTTP referrer restrictions, ensure your app's domain (including localhost for development) is listed.
1// Symptoms:2// - auth/network-request-failed on signIn or signUp3// - Browser Network tab shows 403 on identitytoolkit.googleapis.com4// - Works in one environment but not another56// Fix in Google Cloud Console:7// 1. APIs & Services > Credentials > Click your API key8// 2. Under 'API restrictions':9// - 'Don't restrict key' (safest for web)10// - OR allow: Identity Toolkit API, Token Service API11// 3. Under 'Application restrictions' > HTTP referrers:12// - Add: localhost, localhost:*, your-domain.com/*Expected result: Auth requests to identitytoolkit.googleapis.com return 200 instead of 403.
Fix CORS issues for web applications
Fix CORS issues for web applications
CORS errors prevent the browser from reaching Firebase's servers. This usually happens when a proxy server, browser extension, or service worker intercepts and modifies requests. Check the browser Network tab for CORS-related errors on requests to googleapis.com. Remove or configure any proxy middleware that might intercept auth requests.
1// Symptoms:2// - Console shows 'CORS policy' error alongside network request failed3// - Network tab shows preflight OPTIONS request failing45// Common causes:6// 1. A development proxy intercepting Firebase requests7// 2. A service worker caching or blocking auth endpoints8// 3. A browser extension (ad blocker, privacy tool) blocking Google domains910// Fix for Vite proxy (vite.config.ts):11// Do NOT proxy Firebase domains. Only proxy your own API:12export default defineConfig({13 server: {14 proxy: {15 '/api': 'http://localhost:3001',16 // Do NOT add entries for googleapis.com17 }18 }19})Expected result: Auth requests reach Firebase servers directly without CORS or proxy interference.
Fix Android internet permission issues
Fix Android internet permission issues
On Android, the app needs the INTERNET permission to make network requests. React Native and native Android apps must declare this in AndroidManifest.xml. Additionally, starting with Android 9, cleartext HTTP traffic is blocked by default. Firebase uses HTTPS so this should not be an issue, but custom proxy configurations might route through HTTP.
1<!-- android/app/src/main/AndroidManifest.xml -->2<manifest xmlns:android="http://schemas.android.com/apk/res/android">3 <!-- Add these permissions -->4 <uses-permission android:name="android.permission.INTERNET" />5 <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />67 <application8 android:usesCleartextTraffic="false"9 ...>10 </application>11</manifest>Expected result: The Android app can reach Firebase's servers and authentication works.
Fix Firebase Emulator connectivity issues
Fix Firebase Emulator connectivity issues
When using the Firebase Auth Emulator, the 'network request failed' error often means your app is trying to reach the production auth server instead of the emulator, or the emulator is not running. Call connectAuthEmulator() before any auth operations. Make sure the emulator is running on the expected port (default 9099) and the host is reachable from your app.
1import { getAuth, connectAuthEmulator } from 'firebase/auth'23const auth = getAuth()45// Connect to the emulator in development only6if (process.env.NODE_ENV === 'development') {7 connectAuthEmulator(auth, 'http://127.0.0.1:9099', {8 disableWarnings: true,9 })10}1112// For React Native or mobile, use your machine's IP:13// connectAuthEmulator(auth, 'http://192.168.1.100:9099')Expected result: Auth operations connect to the local emulator instead of production Firebase servers.
Handle transient network failures gracefully
Handle transient network failures gracefully
Even with correct configuration, network requests can fail due to temporary connectivity issues, server-side problems, or mobile network transitions. Implement retry logic for auth operations and show meaningful error messages to users instead of raw Firebase errors.
1import { signInWithEmailAndPassword, AuthError } from 'firebase/auth'23async function signInWithRetry(4 auth: any,5 email: string,6 password: string,7 maxRetries = 28) {9 for (let attempt = 0; attempt <= maxRetries; attempt++) {10 try {11 return await signInWithEmailAndPassword(auth, email, password)12 } catch (error) {13 const authError = error as AuthError14 if (15 authError.code === 'auth/network-request-failed' &&16 attempt < maxRetries17 ) {18 // Wait before retrying (exponential backoff)19 await new Promise(r => setTimeout(r, 1000 * (attempt + 1)))20 continue21 }22 throw error23 }24 }25}Expected result: Transient network failures are retried automatically and persistent failures show a clear message.
Complete working example
1import {2 getAuth,3 connectAuthEmulator,4 signInWithEmailAndPassword,5 createUserWithEmailAndPassword,6 AuthError,7 User,8} from 'firebase/auth'910const auth = getAuth()1112// Connect to emulator in development13if (process.env.NODE_ENV === 'development') {14 connectAuthEmulator(auth, 'http://127.0.0.1:9099', {15 disableWarnings: true,16 })17}1819interface AuthResult {20 user?: User21 error?: string22}2324async function withNetworkRetry<T>(25 operation: () => Promise<T>,26 maxRetries = 227): Promise<T> {28 for (let attempt = 0; attempt <= maxRetries; attempt++) {29 try {30 return await operation()31 } catch (error) {32 const authError = error as AuthError33 const isNetworkError =34 authError.code === 'auth/network-request-failed'35 if (isNetworkError && attempt < maxRetries) {36 await new Promise((r) => setTimeout(r, 1000 * (attempt + 1)))37 continue38 }39 throw error40 }41 }42 throw new Error('Max retries exceeded')43}4445export async function safeSignIn(46 email: string,47 password: string48): Promise<AuthResult> {49 try {50 const { user } = await withNetworkRetry(() =>51 signInWithEmailAndPassword(auth, email, password)52 )53 return { user }54 } catch (error) {55 const authError = error as AuthError56 if (authError.code === 'auth/network-request-failed') {57 return { error: 'Unable to connect. Check your internet connection.' }58 }59 return { error: authError.message }60 }61}6263export async function safeSignUp(64 email: string,65 password: string66): Promise<AuthResult> {67 try {68 const { user } = await withNetworkRetry(() =>69 createUserWithEmailAndPassword(auth, email, password)70 )71 return { user }72 } catch (error) {73 const authError = error as AuthError74 if (authError.code === 'auth/network-request-failed') {75 return { error: 'Unable to connect. Check your internet connection.' }76 }77 return { error: authError.message }78 }79}Common mistakes when fixing Network Request Failed in Firebase Auth
Why it's a problem: Restricting the Firebase API key to specific APIs and accidentally blocking Identity Toolkit
How to avoid: In Google Cloud Console, ensure your API key allows the Identity Toolkit API and Token Service API. The safest option for web is no API restrictions with HTTP referrer restrictions only.
Why it's a problem: Using localhost in connectAuthEmulator on systems with IPv6, causing connection failures
How to avoid: Use http://127.0.0.1:9099 instead of http://localhost:9099. IPv6 resolution of localhost can cause connection issues on some operating systems.
Why it's a problem: Forgetting to add INTERNET permission in Android manifest for React Native apps
How to avoid: Add <uses-permission android:name='android.permission.INTERNET' /> to AndroidManifest.xml. This permission is required for any network requests.
Why it's a problem: A browser extension blocking requests to Google domains
How to avoid: Test in an incognito window with extensions disabled. If auth works there, identify and configure the blocking extension (common culprits: ad blockers, privacy tools).
Best practices
- Test auth operations in an incognito window to isolate browser extension issues
- Use 127.0.0.1 instead of localhost for emulator connections to avoid IPv6 problems
- Implement retry logic with exponential backoff for transient network failures
- Show user-friendly error messages instead of raw Firebase error codes
- Check the browser Network tab for failed requests to googleapis.com as the first debugging step
- Do not over-restrict your Firebase API key in Google Cloud Console
- Use connectAuthEmulator only in development, gated behind an environment check
Still stuck?
Copy one of these prompts to get a personalized, step-by-step explanation.
My Firebase Auth calls fail with 'network request failed' in my React app. It works in some browsers but not others. Show me how to diagnose whether it's a CORS issue, API key restriction, or browser extension, and provide a sign-in function with retry logic for network failures.
Debug 'network request failed' errors in Firebase Auth. Create a network-safe authentication module with retry logic that handles transient failures, connects to the Auth emulator in development, and provides user-friendly error messages for network issues.
Frequently asked questions
What exactly causes the 'auth/network-request-failed' error?
This error fires when the Firebase SDK cannot complete an HTTP request to Google's authentication servers (identitytoolkit.googleapis.com). Causes include no internet, firewall blocks, CORS interference, API key restrictions, or browser extensions blocking Google domains.
Why does auth work on desktop but fail on mobile?
Mobile-specific causes include missing INTERNET permission on Android, cellular networks blocking certain domains, or the app trying to reach an emulator on localhost (which does not resolve to the development machine on a physical device).
How do I test if my API key is blocking auth?
Open the browser Network tab, attempt to sign in, and look for requests to identitytoolkit.googleapis.com. If they return 403, your API key restrictions are blocking the Identity Toolkit API.
Can a VPN cause this error?
Yes, some VPNs block or throttle requests to Google services. Try disconnecting the VPN to test. If auth works without VPN, configure the VPN to allow googleapis.com domains.
Does Firebase Auth work offline?
Firebase Auth caches the current user session locally, so a previously signed-in user remains authenticated offline. However, new sign-in and sign-up operations always require an internet connection and will throw network-request-failed when offline.
Can RapidDev help resolve persistent Firebase Auth connectivity issues?
Yes, RapidDev's engineering team can diagnose complex networking issues including corporate firewall configurations, API key setup, and mobile-specific auth connectivity problems.
Talk to an Expert
Our team has built 600+ apps. Get personalized help with your project.
Book a free consultation