我已经在谷歌云平台上的虚拟机上使用 docker 容器方法安装了 Realm Object Server。容器正在运行,我可以在浏览器中连接并查看 ROS 页面。我可以使用 Realm Studio 连接到它并添加一个用户。
我有一个在 Mac 上本地运行的 nodeJS 应用程序,我正在尝试使用它来登录并写入服务器上的领域。当我运行应用程序时出现错误,返回的用户是一个空对象。不知道我做错了什么。我是 NodeJS 的新手。
代码:
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);
});
输出:
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)
错误@user-methods.js:203:49
const tokenData = json.access_token.token_data;
json 是:{ user_token: { token: 'xxxxxxxx', token_data: { app_id: 'io.realm.Auth', 身份: 'xxxxxxx', salt: 'xxxxxxxx', expires: 1522930743, is_admin: false } } };
所以 json.access_token.token_data 是未定义的,但是 json。user_token.token_data 不会。