react-native-firebase icon indicating copy to clipboard operation
react-native-firebase copied to clipboard

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

Open elalami-m opened this issue 3 months ago • 5 comments

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

  • [x] 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! 🙏

elalami-m avatar Nov 27 '25 15:11 elalami-m

Hi, I'm experiencing the same issue, but on a Samsung Galaxy S25+ running Android 16 (One UI 8.0).

It also doesn’t always happen on the first relaunch: sometimes my app works normally for a while, and then after 1–2 days, when reopening the app, the session/auth state is suddenly not restored.

I also cannot reproduce this on any other Android (non samsung) devices I have available.

nuagoz avatar Nov 28 '25 17:11 nuagoz

Can you try using the latest version v23.5.0

MichaelVerdon avatar Dec 01 '25 10:12 MichaelVerdon

@nuagoz I’ve observed something similar on the Samsung S23 Ultra, so here’s an additional detail that might help confirm the pattern.

On my device, the issue does not require waiting 1–2 days. I can reproduce it instantly by doing the following:

  • Sign in normally (session works).

  • Remove the app from the background (Recent Apps screen).

  • Reopen the app.

After doing this, auth().currentUser becomes null and the Firebase Auth session is not restored, exactly like you described.

This seems to indicate that Samsung’s task-killing behavior (or something related to OneUI’s process lifecycle) is causing Firebase Auth persistence to fail on these devices in release mode.

Still investigating, but wanted to share this observation in case it helps narrow the root cause.

elalami-m avatar Dec 01 '25 15:12 elalami-m

I always throw a link to good old https://dontkillmyapp.com in case they have relevant info for the brand/model - always good to check it

mikehardy avatar Dec 01 '25 18:12 mikehardy

Can you try using the latest version v23.5.0

Thanks it works

elalami-m avatar Dec 05 '25 10:12 elalami-m

Happyt to hear its working now. I will close this ticket now 😄 Feel free to open a new one or reopen if the issue persists

MichaelVerdon avatar Dec 11 '25 12:12 MichaelVerdon