Full Sync - How to implement a global comment system

Hi, I need to implement a shared global realm where users can write new records and delete their previous ones but not delete other users records.

Example, a comment system.

I made it via object permission using query based sync but I cannot understand how to easily implement it via full-sync.

Has someone done it? How have you accomplished that? Thank you.

Good question. Does the documentation provide any insight into permissions on a Full Sync Realm?

Full-Sync permissions

I would be curious as to how you handled it with a query based sync.

Every user can write objects of a class and the permission of deleting an object is granted only to the specific user that has created it.

Going to mention this is a cross post to SO Full Sync - How to implement a global comment system in case someone answers in one place but not the other. Like me :slight_smile:

That is not possible with full sync. Users can either write (meaning create/update/delete) any object or none at all. There’s no possibility to define more granular permissions with full sync.

That’s very disappointing.

Is there any workaround that guarantees me security?

I was thinking of using a node js server that update a global database when something happens in the users databases. Is that a possibility? I would need:

  1. A listener for each new database created on server (If a user that has never connected before do the first connection, a new database is created and so I need to know if there is another database for attaching a listener to it)
  2. A listener for each user database, so users can insert rows in their database offline and when they go back online the node js server can replicate the data on the global database). So on the client I’ll have a property with the sync status (local, synched, deleted ) on the classes I need offline.

Do u think it is a possible solution?

I’ve done some tests and it seems possible to do this easily.

But I have this error:

Failed to parse, or apply received changeset: column type mismatch

That’s my code:


'use strict';

var Realm = require('realm'); 

// the URL to the Realm Object Server
const SERVER_URL = '*********';
var REALM_URL = '********';

// The regular expression you provide restricts the observed Realm files to only the subset you
// are actually interested in. This is done in a separate step to avoid the cost
// of computing the fine-grained change set if it's not necessary.
var NOTIFIER_PATH = '.*';

//declare admin user 
let adminUser = undefined

// The handleChange callback is called for every observed Realm file whenever it
// has changes. It is called with a change event which contains the path, the Realm,
// a version of the Realm from before the change, and indexes indication all objects
// which were added, deleted, or modified in this change
var handleChange = async function (changeEvent) {
  // Extract the user ID from the virtual path, assuming that we're using
  // a filter which only subscribes us to updates of user-scoped Realms.

  console.log("Change")

}


// register the event handler callback
async function main() {
    const credentials = Realm.Sync.Credentials.usernamePassword("****", "****")
    adminUser = await Realm.Sync.User.login(SERVER_URL, credentials)
    Realm.Sync.addListener(REALM_URL, adminUser, NOTIFIER_PATH, 'change', handleChange);
}

main()

Does someone know why?

The problem was that I was using the 4.0.0beta.

With the 3.x it works. I think this will be a good solution for this problem.