Hello All,
I’m like lost with couchbase lite. I have read Channels How to Use Channels in Sync Gateway - The Couchbase Blog and SYNC API Couchbase Capella for Mobile Developers But nothing found relevent. Let me explain what I wanted to do specifically:
We are using Couchbase Server 4.6.2 / Sync Gateway 1.4.1 / Couchbase Lite 1.4.
My Sync Gateway Configuration is below:
{
"log": ["*"],
"adminInterface": ":4985",
"databases": {
"syncDBName": {
"server":"http://192.168.1.188:8091",
"bucket": "bucketname",
"password": "bucketPass",
"users": {
"GUEST": { "disabled": true, "admin_channels": ["public"] },
"syncUser": { "disabled": false, "password": "syncPass", "admin_channels": ["*"] }
},
"sync":`function(doc) {channel(doc.channels);}`
}
}
}
What Exactly I’m trying to do
I’m working on a Xamarin App that’ll have say n numbers of users. So we are having user objects and then the documents that they creates. So Say User A signup and creates documents in App and those are being SYnc to server and same time User B signup the App so both creates their profile and their user document gets updated and sync. Now Another User C signs Up and creates his profile so all A, B and C users have created their profile and Sync Gateway syncronise their user documents.
Now First thing here is needed that Documents of User A should only be accessible to User A and similarly for B and C.
Secnod thing let’s Assume User C is a friend to User A. that means documents of User C should also be accible to User A and vice-versa.
As far as I was able to understand the Sync gateway we can achieve this using Channels for each user to define access and can restrict users using functions like “access”, “requireUser”, “requireAccess” etc. But for this I need to edit the Sync Gateway config file each time new users signup and Also think it like if we have 1 million users it’ll be like never ending config in SYNC Gateway file. So in Short I want to make it dynamic for Sync gateway to understand which user is requesting the Sync and who are friends of this user ( Note: here Sync gateway doesn’t know the user or his friends since they aren’t users of couchbase server or are specified in sync gateway )
Note: for Sync gateway to understand users we are using document naming conventions in the App like ( user_{uid}, and his quiz like quiz_{uid} ) and similar way for channels channel_{uid}.
So here we can attach the channel_{uid} to each document user creates on App side using “doc.channel” property. But how to make Sync gateway understand this and allow access to valid users that is where I’m stuck.
Question 1: if we can pass something to Sync gateway in URL like “http://192.168.1.188:4984/syncDBName/{uid}”??
Or Anything I’m doing wrong here?.
Question 2: If I should be using Sync Gateway Admin API to create each user and add channels for each user document?
Any help will be really appriciated