all working fine with internet connection, but when connection dropped,
my local data are not accessible
but, for create, when i create a new register, its not update or callback for my ui, and when the connection back, it updates right
its like a draftState, waiting for connection
look this video:
0:00 to 0:17 connection on
0:18 to 0:38 connection off
0:39 to end connection on
This only works when you open your app with internet on and later drop the internet connection with your app open. But, it does not work when you open your app with internet off.
@Promit_Rai The first time you launch the app, you must have internet, otherwise you cannot login and get a valid user. Subsequent app starts can then be made offline.
Yeah that is what I mean. For the very first time when I open my app, I open with internet connection , login the user and sync with my cluster. It reads all the data from my cluster. And then I close my app with still user logged in. Then turn off my wifi and open my app. This time it does not return anything.
You should be able to use the new Realm(getConfig(app.currentUser)); API when you are offline to open the cached realm on disk. If this is not happening then please step through it with a debugger and see where your logic is not hitting this API.
with this code, you can connect and open a realm, this is not especifically for offline, because you need to treat your connection and know if is reachable. but it will work for you to understand better
obs: try not to use partition values with space
async function getRealm() {
const app = new Realm.App("your-app-id");
if (app.currentUser) {
// A user had already logged in - open the Realm synchronously
return new Realm(getConfig(app.currentUser));
}
// We don't have a user - login a user and open the realm async
const creds = Realm.Credentials.emailPassword(email, password);
const user = await app.logIn(creds);
return await Realm.open(getConfig(user));
}
function getConfig(user) {
return {
schema: [sessionSchema],
sync: {
user,
partitionValue: "my-partition"
}
};
}