Xamarin example with Gateway from Walrus to server

Hi,

Just succesfully got the example working: xamarin userprofile_sync

Using docker for both couchdb and the gateway. Gateway runs in walrus mode and that works. But now I switched to my real database but this does not work.

The relevant configuration change:
“userprofile”: {
“users”: { "demo@example.com": { “password”: “password”} },
“server”: “http://192.168.1.43:8091”,
“bucket”: “default”,
“num_index_replicas”: 0,
“username”: “Administrator”,
“password”: “********”,

Since I get errors about posting links I cannot add a complete log :frowning:

2019-10-15T11:28:33.770Z [INF] Sync: c:[2199f648] Sent all changes to client

The clients however do not update. What can be wrong here?

Regards, Rob

Save it to a gist and post a link here. It’s not good form to paste long logs into forum threads anyway.

I am a bit further and found quite a lot erros on my side.

However, now I am receiving the following error:
2020-03-04T12:18:26.305Z [INF] HTTP: #013: GET /taakbeheerser/_blipsync
2020-03-04T12:18:26.307Z [INF] HTTP auth failed for username=" test"
2020-03-04T12:18:26.307Z [INF] HTTP: #013: --> 401 Invalid login (2.6 ms)

The config is in my next message.

“interface”:":4984",
“log”: ["*"],
“databases”: {
“taakbeheerser”: {
“server”: “http://192.168.1.205:8091”,
“users”: { “test”: { “password”: “password”} },
“bucket”: “default”,
“username”: “sync_gateway”,
“password”: “password”,
“enable_shared_bucket_access”: true,
“import_docs”: “continuous”,
“num_index_replicas”: 0,
“sync”: function (doc, oldDoc) { if (doc.sdk) { channel(doc.sdk); } }
}
I am supplying the users credential to the BasicAuthenticator for replication. When starting the replicator I see the invalid login in the log file.

Additional question is: I want to have the data in the local db also in the cloud database. How is this supposed to be configured? Are changes via the gateway pushed to the database? In other words, if the auth problem is fixed changes are committed to the couchbase cloud db?

Regards, Rob

HTTP auth failed for username=" test"

There’s a space at the start of the username.

Yes, that’s what the Couchbase Lite replicator does. If you enable pull replication, changes on the server get pulled into the device. If you enable push, changes from the device get pushed to the server.

Oops… I overlooked that, thanks! Now the invalid login is gone.

Once I add something via one instance of the application it is now added in the remote db too. If I start another instance of the application the remote data is not arriving on this instance. I see the events coming in.

A bit further now. Changes are stored in the database but not distributed to other clients. Also a new client does not get the existing data.

I introduced a doc_type and use that as channel. So I subscribe to that channel for replication and also the sync function notifies the channel:

"sync": `function (doc, oldDoc) {
    if (doc.doc_type) {
      channel("channel." + doc.doc_type);
    }
  }`

So what should I do to get the (initial) sync working? I am using the same user accont for multiple clients like the example with the user profile.

Does your user account have access to the channels that the documents are added to? It sounds like it doesn’t.

Where do I define that? I see that with a user I can specify admin channels but in the examples I don’t see any further configuration unless I overlooked something?

You can either specify admin channels in the config, or use the sync function to dynamically assign users or roles to get access to the channel.

Finally got to work again on this… unfortunately still no success.

I added the channel that is specified in ```
channel(“channel.” + doc.doc_type);

into the admin_channels property of the user:
"test": { 
                "password": "password",
                "admin_channels": ["channel.Name"]
                }, 

But the changes are only coming in for the client that is pushing them. Another client with the same user does not receive updates. Also upon starting up a sync is not performed.

What else can I do to tackle this?

Got it working but only when using the ‘access’ method in the sync function. I am using roles now and give that role access via the sync function. I could not get predefined access working.

This does not make sense. You said you were using the user profile tutorial app and it worked with walrus and you switched to a real database and it fails ? ?

access call is an expensive operation so if you are using it within the sync function, you need to ensure that its not redundant.

The "admin_channels": ["channel.Name"] does not seem right. Do you have a channel with the literal name of “channel.Name” ?

What’s your complete sync gateway config.

Here is my config. Without the access call it does not work.

{
“interface”:":4984",
“log”: ["*"],
“databases”: {
“tasks”: {
“server”: “http://192.168.1.205:8091”,
“users”: {
“test”: {
“password”: “password”,
“admin_roles”: [ “duties” ]
},
“GUEST”: {“disabled”: true}
},
“roles”: {
“duties”: {
“admin_channels”: [
“channel.Duty”
]
}
},
“bucket”: “default”,
“username”: “sync_gateway”,
“password”: “password”,
“enable_shared_bucket_access”: true,
“import_docs”: true,
“num_index_replicas”: 0,
“sync”: function (doc, oldDoc) { if (doc.doc_type) { console.log("Adding document to channel" + doc.doc_type); channel("channel." + doc.doc_type); console.log("Giving access to role:duties"); access("role:duties","channel." + doc.doc_type); } }
}
}
}

what’s the “doc_type” in your document?

a property identifying our documents that should be synced

So is there anything wrong in the config? I would like to omit the access call of course.