Why Backend Connection Errors Occur
When your Rork-generated app can't connect to Firebase, Supabase, or other backends, the causes fall into three categories:
- Configuration mistakes — incorrect API keys or missing setup files
- Network and security issues — CORS, firewalls, private networks
- Runtime bugs — insufficient async waits, incorrect state timing
This guide walks through each pattern's symptoms and proven fixes. If you're hitting build errors earlier in the process, the Complete Guide to Fixing Rork App Build Errors is a useful reference.
Error 1: Firebase Configuration Error
Symptoms
Error: Firebase initialization failed
Error: firebaseConfig is undefined
Firebase fails to initialize on app startup with errors in console or Xcode.
Root Causes
- Missing
google-services.json(Android) orGoogleService-Info.plist(iOS) - Firebase config not properly imported in Rork code
- Invalid or typo'd API key
Solutions
Step 1: Download Configuration from Firebase Console
- Go to Firebase Console
- Select your project
- Click Project Settings (gear icon)
- Under "Your apps," select your app
- Download iOS or Android config files
iOS: GoogleService-Info.plist
Android: google-services.json
Step 2: Add to Rork Project
For iOS in Xcode: File → Add Files to Project, select the .plist
For Android: Place google-services.json in android/app/
Step 3: Verify Firebase Initialization Code
Check that Rork's generated code has:
// src/config/firebase.js (example)
import { initializeApp } from 'firebase/app';
const firebaseConfig = {
apiKey: "YOUR_API_KEY",
authDomain: "YOUR_PROJECT.firebaseapp.com",
projectId: "YOUR_PROJECT_ID",
storageBucket: "YOUR_PROJECT.appspot.com",
messagingSenderId: "YOUR_SENDER_ID",
appId: "YOUR_APP_ID",
};
const app = initializeApp(firebaseConfig);
export default app;Ensure all YOUR_* placeholders are replaced with actual values.
Error 2: Supabase Connection Error
Symptoms
Error: Failed to connect to database
Error: SUPABASE_URL or SUPABASE_KEY is undefined
Requests to Supabase fail; network tab shows "CORS error" or "401 Unauthorized."
Root Causes
- Supabase Project URL or Anon Key misconfigured
- CORS not set up
- API key lacks proper permissions
Solutions
Step 1: Retrieve Credentials from Supabase
- Go to Supabase Dashboard
- Select your project
- Settings → API to find:
- Project URL:
https://xxxxx.supabase.co - Anon Key: Long string starting with
eyJhbGc... - Service Role Key: Never expose publicly
- Project URL:
Step 2: Set Environment Variables
For React Native/Expo, create .env:
EXPO_PUBLIC_SUPABASE_URL=https://xxxxx.supabase.co
EXPO_PUBLIC_SUPABASE_ANON_KEY=eyJhbGc...
The EXPO_PUBLIC_ prefix is critical (client-visible variables).
Step 3: Initialize Supabase Client
import { createClient } from '@supabase/supabase-js';
const supabaseUrl = process.env.EXPO_PUBLIC_SUPABASE_URL;
const supabaseAnonKey = process.env.EXPO_PUBLIC_SUPABASE_ANON_KEY;
export const supabase = createClient(supabaseUrl, supabaseAnonKey);Error 3: CORS (Cross-Origin) Error
Symptoms
Access to XMLHttpRequest blocked by CORS policy
Origin 'http://localhost:3000' is not allowed
CORS errors appear in browser console.
Root Causes
- Backend rejects requests from local development (localhost:3000)
- CORS headers not configured
Solutions
Firebase: CORS Not Required
Firebase SDK is client-side, so CORS errors shouldn't occur here. If they do, check custom backend calls.
Supabase: CORS Auto-Enabled
Supabase REST and Realtime APIs support CORS automatically. For custom RPC functions, verify setup.
Custom Backend (Express, etc.):
const cors = require('cors');
app.use(cors({
origin: [
'http://localhost:3000',
'http://localhost:19000', // Expo
'https://yourdomain.com' // production
],
credentials: true
}));Error 4: Invalid Authentication Token
Symptoms
Error: Invalid or missing authentication token
Error: 401 Unauthorized
Works after login, but fails later when token expires.
Root Causes
- Session not auto-refreshing in Firebase/Supabase
- Token refresh logic not implemented
- Token not stored in local storage or secure store
Solutions
Firebase: Auto-Refresh Built-In
Firebase SDK auto-refreshes tokens. Verify with:
import { onAuthStateChanged } from 'firebase/auth';
import { auth } from './firebase.config';
export function useFirebaseAuth() {
const [user, setUser] = useState(null);
useEffect(() => {
const unsubscribe = onAuthStateChanged(auth, (currentUser) => {
setUser(currentUser);
// Token auto-refreshes
});
return unsubscribe;
}, []);
return user;
}Supabase: Refresh Token Management
import AsyncStorage from '@react-native-async-storage/async-storage';
export async function restoreSession() {
const { data, error } = await supabase.auth.refreshSession();
if (error) console.error('Session refresh failed:', error);
return data;
}
// Run on app launch
useEffect(() => {
restoreSession();
}, []);Error 5: Network Security Error
Symptoms
Error: Network request failed
ERR_SSL_PROTOCOL_ERROR
Can't connect to HTTP-based backends.
Root Cause (iOS)
iOS 9+ requires HTTPS by default. HTTP connections need explicit exceptions.
Solutions (iOS)
Add to Info.plist:
<key>NSAppTransportSecurity</key>
<dict>
<key>NSAllowsLocalNetworking</key>
<true/>
<key>NSExceptionDomains</key>
<dict>
<key>localhost</key>
<dict>
<key>NSIncludesSubdomains</key>
<true/>
<key>NSTemporaryExceptionAllowsInsecureHTTPLoads</key>
<true/>
</dict>
</dict>
</dict>Use HTTPS in production. HTTP is development-only.
Root Cause (Android)
AndroidManifest.xml may need android:usesCleartextTraffic configuration.
<application
android:usesCleartextTraffic="true"
...>
</application>Always use HTTPS for production.
Error 6: Data Persistence and Offline Sync Issues
Symptoms
- App shows no data when offline
- Saved data disappears
- No sync after network returns
Root Causes
- Local cache not implemented
- SwiftData (iOS) or Realm (React Native) incomplete setup
- Insufficient offline state management
Solutions
Firebase + iOS: Enable Firestore Persistence
import FirebaseFirestore
let db = Firestore.firestore()
db.settings.isPersistenceEnabled = true
// Offline data now auto-savesSupabase + React Native: Implement Local Cache
import AsyncStorage from '@react-native-async-storage/async-storage';
export async function fetchAndCacheData(table) {
try {
const { data, error } = await supabase
.from(table)
.select();
if (!error) {
// Success: save locally
await AsyncStorage.setItem(
`cache_${table}`,
JSON.stringify(data)
);
return data;
}
} catch (e) {
console.error('Network failed, loading cache');
}
// Load from cache
const cached = await AsyncStorage.getItem(`cache_${table}`);
return cached ? JSON.parse(cached) : null;
}Looking back
90% of database connection errors resolve through correct configuration, valid credentials, and proper CORS setup. The key is reading error messages carefully and checking environment variables.
The truly challenging part is offline sync and real-time synchronization. Rork's generated apps already have the foundational structure—you just fine-tune.
With backend connectivity complete, move forward to Troubleshooting Rork App Publishing — From TestFlight to App Store Release.
For deeper backend architecture knowledge:
Rork-generated apps are production-ready. These errors are systematically solvable. You can do this!