Hello,
TL;DR anonymous auth is OK, but an empty collection is returned
NB: I cannot post more than one image in this post because I’m a new user. Please follow the link to open the images. Thanks.
I’m new to Realm and I try to develop a React Native app that will display a list of contacts. Before this app, I’ve successfully testes the Task demo app.
I use a Realm function with a trigger that periodically:
- fetch contacts from an LDAP API
- create, update or delete contacts in an Altas collection
For now, each users of the mobile app should see the same list of contacts. Therefore, I’ve set the _partition
key to public
in my Contact
document.
I think that my Realm app is configured correctly:
- Schema is correctly configured (and match the schema in the client)
- Sync is enabled and permissions are set to read only
I’ve enabled the anonymous authentication. Authentication is successful because I can see the anonymous users in Realm UI. Therefore, I know that my code is okay regarding the auth.
The React Native code is for now really simple:
import Realm from 'realm';
const app = new Realm.App({
id: 'xxxxx',
});
const credentials = Realm.Credentials.anonymous();
const user = await app.logIn(credentials);
const realm = await Realm.open({
schema: [Contact.schema],
sync: {
user,
partitionValue: 'public',
},
});
const contacts = realm.objects('Contact');
console.log('contacts', contacts);
And I’ve defined the following model:
import Realm from 'realm';
class Contact extends Realm.Object {
static schema: Realm.ObjectSchema = {
name: 'Contact',
primaryKey: '_id',
properties: {
_id: 'objectId',
_partition: 'string',
displayName: 'string',
firstName: 'string',
lastName: 'string',
thumbnail: 'string?',
username: 'string',
countryName: 'string?',
countryCode: 'string?',
jobTitle: 'string?',
jobAffiliate: 'string?',
jobDepartment: 'string?',
jobOffice: 'string?',
email: 'string',
phone: 'string?',
mobilePhone: 'string?',
},
};
}
export default Contact;
The problem is that the collection is always empty.
Realm UI logs return that the Sync is working:
see image _7e96aa7acfb2b8ec1fd4bc7badd69939157b272a hosted at ImgBB — ImgBB
Did I understand the partition system correctly? By setting the partitionValue
parameter to public
in my client app, it should returns the documents in my Contact collection that have _partition: "public"
, right?
Is it possible to use the anonymous authentication with Sync?
Did I miss something?
Thanks!