question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Error when opening synced realm with current user while offline

See original GitHub issue

Steps:

  1. Log into ROS and get a User.
  2. Open a synced realm with this User.
  3. Shut down the ROS.
  4. Restart the app.
  5. Try to open the same realm with the User from step 1.

After after these steps, opening the realm (using new Realm(config)) succeeds, but throws a “Network request failed” error shortly after (this is a React Native red box error and isn’t even catchable with a try/catch around the Realm instantiation).

Code:

export default class App extends Component<Props> {
  constructor() {
    super();
    this.logIn();
  }

  async logIn() {
    let user = Realm.Sync.User.current;

    if (!user) {
      user = await Realm.Sync.User.login(LOGIN_URL, 'test', 'test');
    }

    const config = {
      sync: {
        user,
        url: REALM_URL,
      },
      schema: [],
    };

    const realm = new Realm(config);
  };
}

System:

  • Realm JS SDK Version: 2.3.3
  • Node or React Native: React Native 0.54.2
  • Client OS & Version: iOS
  • Which debugger for React Native: None

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:3
  • Comments:8 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
gonza-litocommented, Aug 7, 2019

hi @kneth , so for what I understand, the problem is this line right here: https://github.com/realm/realm-js/blob/2490d80d65782403a63d5638cd421d43737cf01f/lib/user-methods.js#L326

It fails with an error that is pretty visible, and for the case in question it would be nice to have a way to fail grafully since there’s no connection available, allowing for the error to be dismissed by the user or handled elsewhere.

My first idea, is to throw that error up in the stack so that it can handled by whoever is calling refreshAccessToken, but I think i’m lacking some context over this.

Another more simple approach is to just remove the console for a log tool so that we can ignore the error message.

0reactions
sync-by-unito[bot]commented, Jan 12, 2021

➤ Kenneth Geisshirt commented:

We have changes the API in Realm JS v10. Moreover, it is possible to specify different opening behaviour in the configuration which will help is the offline case.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Unable to open synced realm offline - MongoDB
I am making a React Native app using Realm Sync and I am in dire need of guidance regarding how to use it...
Read more >
Not able to work offline in realm with .net sdk - Stack Overflow
So by using this logic, it will find the user even in offline mode and will not go further to process the login...
Read more >
Building Offline-First Mobile Applications Using MongoDB ...
By default, Sync is disabled on all Realm apps. We need to enable it using the Realm UI before we can sync the...
Read more >
Help needed: unable to open synced Realm offline : r/mongodb
schema], sync: { user: user, partitionValue: `user=${user.id}`, error: errorSync, }, }; Realm.open(config).then((userRealm) => { console.log('> ...
Read more >
Build offline-first mobile application using MongoDB Realm ...
Realm's mobile database is an open source, developer-friendly alternative to CoreData ... sync: { user: app.currentUser, // loggedIn User
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found