React Native Realm app crashing when registering a user and signing in immediately after

I’ve been developing a React Native app using Realm for data syncing for a while now. My data seems to be syncing as expected but recently, I tried modifying the authorization portion of the app and I’m running to issues where the app is crashing. I’ve narrowed down where the crash is occurring but I haven’t been able to find any helpful logs, either from the Realm dashboard or putting console logs in my code. My goal is to try to figure out what’s breaking.


Repo steps:

  • While logged in as a user, log out (app.currentUser.logOut())
    • I feel like this is important since the break seems to happen when reopening the Realm after a user change
  • Register a user (app.emailPasswordAuth.registerUser())
    *Sign in with new user

Result: app crashes when the code reaches Realm.open(config), never getting into the .then block or the .catch block


The Realm dashboard logs indicate a successful sync and no other error
Reopening the app after the crash, the user is logged in and the app behaves as expected.


Here is the useEffect that calls Realm.open

useEffect(() => {
    const OpenRealmBehaviorConfiguration = {
      type: 'openImmediately',
    };
    const config = {
      schema: [EntrySchema, SubjectSchema, LearnerSchema],
      sync: {
        user,
        partitionValue: user.id,
        error: (_session, error) =>
          console.log('sync error', error.name, error.message),
        newRealmFileBehavior: OpenRealmBehaviorConfiguration,
        existingRealmFileBehavior: OpenRealmBehaviorConfiguration,
        initialSubscriptions: {
          update: (subs, _realm) => {
            subs.add(_realm.objects('Entry'));
            subs.add(_realm.objects('Subject'));
            subs.add(_realm.objects('Learner'));
          },
        },
        rerunOnOpen: true,
      },
    };
    Realm.open(config)
      .then(_realm => {
        setRealm(_realm);
      })
      .catch(e => console.warn('Realm open error:', e));

    return () => {
      if (realm) {
        realm.close();
        setRealm(null);
      }
    };
  }, [user]);

Here are my package deps:

  "dependencies": {
    "@react-native-community/datetimepicker": "^6.3.2",
    "@react-native-picker/picker": "^2.4.4",
    "@react-navigation/native": "^6.0.11",
    "@react-navigation/native-stack": "^6.7.0",
    "@realm/react": "^0.3.2",
    "react": "18.0.0",
    "react-native": "0.69.3",
    "react-native-background-timer": "^2.4.1",
    "react-native-get-random-values": "^1.8.0",
    "react-native-safe-area-context": "^4.3.1",
    "react-native-screens": "^3.15.0",
    "react-native-toast-message": "^2.1.5",
    "react-native-vector-icons": "^9.2.0",
    "react-native-wheel-pick": "^1.2.0",
    "realm": "^10.19.5"
  },

updating the realm package to 10.24.0 seems to have resolved the issue

This topic was automatically closed 5 days after the last reply. New replies are no longer allowed.