Opening a *previously* Synced Realm without a Connection

After today’s meet-up about Cosync JWT, I modified some of my code to use the Custom JWT that they provide and am now saving the JWT token in the keychain during login and using that to reauthenticate when a user returns to the app.

The issue I’m having is that if the user really wants to be able to do offline first, the realm needs to be able to open without signal. If the app is open and the user is logged in and then loses signal, the app continues to work.

But if there is no signal when the app is opened, I check for a stored token and then attempt to log in. Obviously, that fails.

Is there a way to open the realm locally with a stored token without reconnecting to the server to truly do offline first?

If you do not call logOut() then the user is cached and the app can open the realm by passing in the cached user reference to the realm without signal. If you want to use the app offline I’d recommend not calling logOut()

1 Like

Great, so then we don’t really need to log the email/password/jwt-token.

But where is that user cached?

Is there somewhere in the docs that shows how to pass in the cached user reference?

I’m not using logOut() unless they specifically tap a button to log out.

Thanks.

Hey @Ian_Ward,

I did try it in a SwiftUI app and this seemed to work:

if app.currentUser != nil {
                  self.loggedIn = true
              } 

Wondering if there are any drawbacks to using this. Does this cache timeout eventually? Is there anything else I need to think about with this?

Thanks.

–Kurt

Is there anything like this for React Native?

I’m attempting to check for app.currentUser, but it doesn’t appear to be finding the cached user like it does in the SwiftUI app.

@Ian_Ward @Kenneth_Geisshirt

Thanks.

–Kurt

Yes - this is how our tutorial works -

Thanks!

I’m assuming this should work for Anonymous login as well as Email/Password, right?

–Kurt