Skip to content

🚨 Firebase Auth session not persisting on Samsung S23 Ultra (React Native – Release mode only) #8781

@elalami-m

Description

@elalami-m

Issue

I'm facing an issue where Firebase Authentication session is not being restored on Samsung S23 Ultra devices, but only in release mode.

What happens

  • In development builds, auth persistence works perfectly.
  • In release builds on Samsung S23 Ultra, auth().currentUser becomes null after restarting the app.
  • onAuthStateChanged fires as expected, but Firebase does NOT restore the cached session.
  • This only occurs on Samsung S23 Ultra (Android 14 / OneUI).
  • Works correctly on all other devices (Pixel, Xiaomi, emulator, iOS).

No errors appear in logcat during restore.

I suspect the issue might be:

  • Samsung's aggressive background restrictions
  • SharedPreferences restore not being triggered
  • R8 stripping something even without warnings
  • Some Firebase internal behavior specific to Samsung + Android 14

Relevant JS code (simplified)

Hydration sequence

hydrate: async () => {
  if (authUnsubscribe) {
    authUnsubscribe();
  }
  if (userListenersUnsubscribe) {
    userListenersUnsubscribe();
  }

  const handler = createAuthStateHandler(set, get, (unsubscribe) => {
    userListenersUnsubscribe = unsubscribe;
  });

  authUnsubscribe = await handler();
},

Auth state handler

export function createAuthStateHandler(
  set: (partial: Partial<AuthState>) => void,
  get: () => AuthState,
  setUserListenersUnsubscribe: (unsubscribe: (() => void) | null) => void
) {
  return async () => {
    const auth = getAuth();
    console.log('[AuthStateHandler] register listener', {
      platform: Platform.OS,
      platformVersion: Platform.Version,
    });

    return onAuthStateChanged(auth, async (user) => {
      console.log('[AuthStateHandler] onAuthStateChanged triggered', {
        user: user?.uid ?? null,
        currentUser: auth.currentUser?.uid,
        listenerTime: Date.now(),
      });

      if (user) {
        await handleAuthenticatedUser(
          user,
          set,
          get,
          setUserListenersUnsubscribe
        );
      } else {
        console.log('listener:user-null');
        await handleSignedOutUser(set);
      }
    });
  };
}

Project Files

(I’m using Expo + RN Firebase. No modifications to Android native files relevant to persistence.)

Javascript

package.json:

   "@react-native-firebase/app": "^22.4.0",
    "@react-native-firebase/auth": "^22.4.0",
    "@react-native-firebase/database": "^22.4.0",
    "@react-native-firebase/firestore": "^22.4.0",
    "@react-native-firebase/functions": "^22.4.0",
    "@react-native-firebase/in-app-messaging": "^22.4.0",
    "@react-native-firebase/installations": "^22.4.0",
    "@react-native-firebase/messaging": "^22.4.0",
    "@react-native-firebase/storage": "^22.4.0",

iOS

(irrelevant to the issue, works fine)


Android

Persistence-related details

  • Using default Firebase Auth persistence (SharedPreferences)
  • Not using any custom storage override
  • No ProGuard/R8 warnings related to Firebase
  • Using MMKV but NOT for auth persistence

Environment

react-native info output: N/A (Expo environment)

Platform

  • Android
  • iOS
  • Both

react-native-firebase version

latest (auth + app modules)

Firebase modules

@react-native-firebase/auth

TypeScript

Yes


Additional Notes

What I tried

  • Clearing app data
  • Fully reinstalling release build
  • Disabling battery optimizations on the device
  • Testing with and without ProGuard/R8
  • Checking that SharedPreferences is accessible
  • Verified works perfectly on all other tested Android devices

Request

Is this a known issue with Firebase Auth persistence on Samsung devices or Android 14?
Any guidance on how to diagnose why Firebase fails to restore a session on Samsung S23 Ultra only in release builds would be appreciated.

Happy to provide:

  • Full logs
  • A reproducible minimal project
  • A screen recording

Thanks in advance! 🙏

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions