I am creating a xamarin app that uses couchbase lite , sync gateway and couchbase server ,
I followed this tutorial : https://docs.couchbase.com/userprofile-couchbase-mobile/sync/userprofile/xamarin/userprofile_sync.html (but I used server : 127.0.0.1 instead of walrus )
here it is creating users from the config file of sync gateway to be able to sync the user and its data on the server , but I need to create the user from the application itself not from the config file , how can I do this please ?
here is the config file where I create the users :
{
"log": ["*","Debug"],
"databases": {
"userprofile": {
"server": "http://127.0.0.1:8091",
"bucket": "userprofile",
"username": "Maria",
"password": "123456",
"enable_shared_bucket_access": true,
"import_docs": "continuous",
"num_index_replicas": 0,
"delta_sync" :{"enabled":true},
"users": {
"Maria": { "password": "123456"},
"Mina": { "password": "123456"},
"GUEST": { "disabled": false, "admin_channels": ["*"] }
},
"sync": `
function sync(doc, oldDoc) {
/* Authorization */
// Verify the user making the request is the same as the one in doc's email
requireUser(doc.email);
/* Data Validation */
if (!isDelete()) {
// Validate the presence of email fields
validateNotEmpty("email", doc.email);
// Check if document is being created / added for first time
// We allow any user to create the document
if (isCreate()) {
// Validate that the document Id _id is prefixed by owner.
var expectedDocId = "user" + "::" + doc.email;
if (expectedDocId != doc._id) {
throw({forbidden: "user doc Id must be of form user:email"});
}
} else {
// Validate that the email hasn't changed.
validateReadOnly("email", doc.email, oldDoc.email);
}
}
/* Routing */
// Subsequent updates to document must be authorized
var email = getEmail();
// Add doc to the user's channel.
channel("channel." + email);
/* Access Control */
// Give user read access to channel
if (!isDelete()) {
// Deletion of user document is essentially deletion of user
access(email,"channel." + email)
}
// get type property
function getType() {
return (isDelete() ? oldDoc.type : doc.type);
}
// get email Id property
function getEmail() {
return (isDelete() ? oldDoc.email : doc.email);
}
// Check if document is being created/added for first time
function isCreate() {
// Checking false for the Admin UI to work
return ((oldDoc == false) || (oldDoc == null || oldDoc._deleted) && !isDelete());
}
// Check if this is a document update
function isUpdate() {
return (!isCreate() && !isDelete());
}
// Check if this is a document delete
function isDelete() {
return (doc._deleted == true);
}
// Verify that specified property exists
function validateNotEmpty(key, value) {
if (!value) {
throw({forbidden: key + " is not provided."});
}
}
// Verify that specified property value has not changed during update
function validateReadOnly(name, value, oldValue) {
if (value != oldValue) {
throw({forbidden: name + " is read-only."});
}
}
}
`
}
}
}