Search code examples
react-nativejwtrealm

Empty object user when authenticating with Realm.Credentials.jwt(token) and Realm connection issue with RN hot reload


I am trying to use Mongo Realm (v10.0.0-beta.9) ; I use a JWT authentication (token being generated by AWS Cognito). It works pretty well since a user has been created (in Mongo Realms Users menu) and I was able to insert a data in my realm. But...

1. Empty user object

One strange thing nevertheless: the user I get from the authentication is empty

  const credentials = Realm.Credentials.custom(jwt)
    // Authenticate the user
  const user: Realm.User = await app.logIn(credentials)
  console.log("logged in with Jwt, user:", user) // display "logged in with Jwt, user: {}"

Is it normal? Examples speak about a identity field: console.log(`Logged in as ${newUser.identity}`);

2. React Native hot reload

A bothering thing: I can't reconnect to a realm when reloading the app (pressing r in the console where I npm started). I don't get any error, I just get... nothing. No log appears in Realm console. The only solution I get is to kill the app, then restart it.

Did I miss a trick to handle that reconnection with RN hot relad?


Solution

  • I've had some troubles converting any Realm objects to printable strings; I always get {} just like you do. I think it could be related to this (unresolved) task on their GitHub.

    On a similar note, there are some bugs in Realm's authentication system. I'm trying to get email/password, Facebook, and Google authentication going in my application but all of them currently seem to be broken on Realm's side.

    Here are some related issues on their GitHub that you can follow for a solution.

    I don't have any information about JWT specifically but given these other authentication issues there's a good chance the issue isn't on your side. I recommend opening an Issue on their repository.