Error when opening synced realm with current user while offline
See original GitHub issueSteps:
- Log into ROS and get a
User
. - Open a synced realm with this
User
. - Shut down the ROS.
- Restart the app.
- 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:
- Created 5 years ago
- Reactions:3
- Comments:8 (5 by maintainers)
Top 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 >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
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.
➤ 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.