Below is my sync gateway function, i want to allow some documents (which has type=“public_access”) to replicate to all users, How do i do that? I added channel as public for those documents, but it does not work.
Grant all users access to your “public” channel. This could be done either via the Admin REST API, or by an access grant in your sync function.
Use Sync Gateway’s built-in public channel “!”. Channeling documents to the “!” channel will make them accessible to all users without any additional security required for those users.
{
“log”: [“CRUD”, “REST+”, “Access”],
“databases”: {
“testdemo”: {
“server”: “http://ravideveloper:8091/”,
“users”: {
“ravi”: {
“disabled” : false,
“password”: “ravi@123”,
“admin_channels”:["*"]
}
},
“sync”: function(doc, oldDoc) { // NOTE this function is the same across the iOS, Android, and PhoneGap versions. if (doc.type == "task") { if (!doc.list_id) { throw({forbidden : "items must have a list_id"}) } channel("task-"+doc.list_id); } else if (doc.type == "list") { channel("list-"+doc._id); if (!doc.owner) { throw({forbidden : "list must have an owner"}) } if (oldDoc) { var oldOwnerName = oldDoc.owner.substring(oldDoc.owner.indexOf(":")+1); requireUser(oldOwnerName) } var ownerName = doc.owner.substring(doc.owner.indexOf(":")+1); access(ownerName, "list-"+doc._id); } }
}
}
}