我可以在本地注册用户(不是管理员),登录和存储数据。 但是我的程序没有将数据同步到ROS2。
据我看到文档,可能会将Realm.Sync.addListener
与admin
一起使用。
我认为管理员用户可以访问所有对象数据。是错的?
const addListener = (user) => new Promise((resolve, reject) => {
Realm.Sync.addListener('realm://usme-ros.usme.local:9080', user, '.*', 'change', (back) => {
console.log(back);
});
});
const registerUser = () => new Promise((resolve, reject) => {
Realm.Sync.User.register(URL, username, password, (err, res) => {
if (err) {
return reject(err);
}
console.log('finish register');
resolve();
})
});
const login = () => new Promise((resolve, reject) => {
Realm.Sync.User.login(URL, username, password, (err, user) => {
if (err) {
return reject(err);
}
resolve(user);
})
});
const registerVisit = (token) => new Promise((resolve, reject) => {
const visitSchema = {
name: 'Visit',
properties: {
id: 'int',
oneday_id: 'string',
arrival_date: 'string',
departure_date: 'string',
latitude: 'double',
longitude: 'double',
is_hidden: 'bool',
}
};
Realm.openAsync({ schema: [visitSchema] }, (err, realm) => {
if (err) {
return reject(err);
}
realm.write(() => {
realm.create('Visit', {
id: 1,
oneday_id: "ABCD-EFGH-IJKL-MNOP-QRST",
arrival_date: "2017-11-05 11:11:11",
departure_date: "2017-11-05 22:22:22",
latitude: 23.1234567,
longitude: 12.34567,
is_hidden: false,
});
});
resolve();
});
});
login()
.then((user) => addListener(user)
.then(() => registerVisit())
.catch(err => console.log(err)));