Offline support and handle session if user is already login

We have downloaded and created the give application

We have followed the following steps

  1. Login as first user kashee@gmail.com.
  2. Login as second user shankar@gmail.com.
  3. Had some conversation with shankar@gmail.com using chat.
  4. Now exit the app (kill the app).
  5. Now go offline, switch off the network in mobile.
  6. Now opening the app again.
  7. Now again i am able to see login screen.

We need that if user is already login then it should not ask to login again and want to see the conversation had with shankr@gmail.com even if mobile network is off. expecting the data should persist locally in device or realm SDK

in Firebase / AWS Amplify this functionality is working so can you please help to resolve this problem as soon as possible.

I know this is an old thread, but just for the record, Realm caches de user when you log in for the first time.

Sou, you can do things like this (React Native version):

const app = new Realm.App(appConfig);

const credentials = Realm.Credentials.jwt(accessToken);

try {
  // Try to login, but ignore the error to allow continue offline.
  await app.logIn(credentials);
} catch (err) {
  console.warn(err);
}

if (app.currentUser) {
  // Ensure that exists a cached or logged user
  throw new Error('Realm login failed: current user not found');
}

const realm = await Realm.open({
      schema: config.schema,
      schemaVersion: config.schemaVersion,
      sync: {
        user: app.currentUser,
        partitionValue: config.partition,
        ...
      },
    });

// Done!

Docs: https://www.mongodb.com/docs/realm/sdk/node/examples/open-and-close-a-realm/#open-a-synced-realm-while-offline