4

I've installed Realm Object Server using the docker container method on a VM on the google cloud platform. The container is running and I am able to connect in a browser and see the ROS page. I am able to connect to it using Realm Studio and add a user.

I have a nodeJS app running locally on a Mac and I'm trying to use that to sign in and write to realm on the server. When I run the app I get an error and the user returned is an empty object. Not sure what I'm doing wrong. I'm new to NodeJS.

Code:

        var theRealm;
    const serverUrl = "http://xx.xx.xx.xx:9080";
    const username = "xxxx";
    const password = "xxxx";

    var token = "long-token-for-enterprise-trial";
    Realm.Sync.setFeatureToken(token);

    console.log("Will log in user");
    Realm.Sync.User.login(serverUrl, username, password)
        .then(user => {
                                                           ``
        // user is logged in
        console.log("user is logged in " + util.inspect(user));
            // do stuff ...
            console.log("Will create config");
            const config = {
                schema:[
                    schema.interventionSchema,
                    schema.reportSchema
                ],
                sync: {
                    user: user,
                    url: serverUrl
                }
            };
            console.log("Will open realm with config: " + config);
            const realm = Realm.open(config)
                .then(realm => {
                    // use the realm instance here
                    console.log("Realm is active " + realm);
                    console.log("Will create Realm");
                    theRealm = new Realm({
                        path:'model/realm_db/theRealm.realm',
                        schema:[
                            schema.interventionSchema,
                            schema.reportSchema
                        ]
                    });
                    console.log("Did create Realm: " + theRealm);
                })
                .catch(error => {
                    // Handle the error here if something went wrong
                    console.log("Error when opening Realm: " + error);
                });
            })
        .catch(error => {
            // an auth error has occurred
            console.log("Error when logging in user: " + error);
        });

Output:

Will log in user
Server is running...
user is logged in {}
Will create config
Will open realm with config: [object Object]
TypeError: Cannot read property 'token_data' of undefined
    at performFetch.then.then (/pathToProject/node_modules/realm/lib/user-methods.js:203:49)
    at <anonymous>
    at process._tickCallback (internal/process/next_tick.js:188:7)
TypeError: Cannot read property 'token_data' of undefined
    at performFetch.then.then (/pathToProject/node_modules/realm/lib/user-methods.js:203:49)
    at <anonymous>
    at process._tickCallback (internal/process/next_tick.js:188:7)

Error @ user-methods.js:203:49

const tokenData = json.access_token.token_data;

json is: { user_token: { token: 'xxxxxxxx', token_data: { app_id: 'io.realm.Auth', identity: 'xxxxxxx', salt: 'xxxxxxxx', expires: 1522930743, is_admin: false } } };

So json.access_token.token_data is undefined but json. user_token.token_data would not be.

Christian Fox
  • 390
  • 2
  • 15

1 Answers1

0

I would suggest you to try the ROS connection with realm studio in that u can check logs as well which will help you to fix the error. If your still not able to fix then you can contact Realm support team even they helped me to fix the issue of ROS connection in Xamarin Forms using Docker.

Judson Abraham
  • 316
  • 2
  • 11
  • 37