CBlite & sync_gateway facebook auth error

I am trying to authenticate CBLite and sync gateway using facebook auth
The facebook auth is sometimes working and sometimes it is giving the following error

401 Facebook verification server status 400

I want to completely remove the facebook auth and integrate auth with basic auth using sync_gateway username and password mentioned in the service_config.

How do I achieve this? Please Help

Technology: Cordova
Sync_gateway Version: 2.1
Couchbase Version : 6.1
CBlite I am using a plugin : com.couchbase.lite.phonegap which uses CBLite Version 1.4

What do you mean by service_config? Do you mean the sync gateway JSON config? If so then any user create has the ability to use basic auth by default (using the password specified in the config, or via REST API creation). There is not any special setup required.

Yes by service-config, I mean Sync Gateway JSON config,
and I have created an user in the Sync Gateway JSON config

{
 "interface": ":4984",
 "adminInterface": ":4985",
"log": ["CRUD", "CRUD+", "HTTP", "HTTP+", "Access", "Cache", "Shadow", "Shadow+", "Changes", "Changes+"],
"facebook": {
"register": false
 },
"databases": {
  "techspin": {
      "server": "http://localhost:8091",
      "bucket": "techspin",
      "username" : "Admin",
      "password" : "password",
      "import_docs": "continuous",
      "enable_shared_bucket_access": true,
       "use_views": true,
       "send_www_authenticate_header": false,          
       "num_index_replicas": 0,
     
      "sync": `
                function(doc, oldDoc) {
                if (doc.type == "task") {
                  if (!doc.list_id) {
                    throw({forbidden : "items must have a list_id"})
                  }
                  channel("company-list");
                } else if (doc.type == "list") {
                  channel("company-list");
                  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);
                  if (Array.isArray(doc.members)) {
                    var memberNames = [];
                    for (var i = doc.members.length - 1; i >= 0; i--) {
                    memberNames.push(doc.members[i].substring(doc.members[i].indexOf(":")+1))
                    };
                    access(memberNames, "list-"+doc._id);
                  }
                } else if (doc.type == "profile") {
                  channel("profiles");
                  var user = doc._id.substring(doc._id.indexOf(":")+1);
                  if (user !== doc.user_id) {
                    throw({forbidden : "profile user_id must match docid"})
                  }
                  requireUser(user);
                  access(user, "profiles"); // TODO this should use roles
                }
              }        `,
              "users" : {
                "sync_gateway" : {"password":"password",
                "admin_channels": ["*"]
                }, 
                "GUEST" : {"disabled" : false,
                "admin_channels": ["*"]
                }
              }
             
      }
  }
  }

The above is my sync Config Json file.

After that what issue are you facing?

Sorry for the Late reply, after this the data is not getting synced constantly. Sometimes it is getting synced and sometimes it is giving the below error

#3502 POST /techspin/_facebook (as GUEST)
#3502. → 401 Facebook verification server status 400 (49.0 ms)

this is my triggerSync Function

function triggerSync(cb, retryCount) {
if (!config.user) {
    return log("no user")
}
var remote = {
    url : config.site.syncUrl,
    auth : {facebook : {email : config.user.email}} // why is this email?
  },

push = {
    source : appDbName,
    target : remote,
    continuous : true
}, pull = {
    target : appDbName,
    source : remote,
    continuous : true
},

pushSync = syncManager(config.server, push),
pullSync = syncManager(config.server, pull)

log("pushSync", push)

if (typeof retryCount == "undefined") {
    retryCount = 3
}
var challenged = false;
function authChallenge() {
    if (challenged) {return}
    challenged = true;
    pushSync.cancel(function(err, ok) {
        pullSync.cancel(function(err, ok) {
            if (retryCount == 0) {return cb("sync retry limit reached")}
            retryCount--
            get_new_token(function(err, ok) {
              triggerSync(cb, retryCount)
            })
        })
    })
}
pushSync.on("auth-challenge", authChallenge)
pullSync.on("auth-challenge", authChallenge)

pushSync.on("error", function(err){
    if (challenged) {return}
    cb(err)
})
pushSync.on("connected", function(){
    pullSync.start()
})
pullSync.on("error", function(err){
    if (challenged) {return}
    cb(err)
})
pullSync.on("connected", function(){
    cb()
})
// setTimeout(function(){
    pushSync.start()
// }, 10000)
}

Instead of facebook auth

    var remote = {
    url : config.site.syncUrl,
    auth : {facebook : {email : config.user.email}} 
  }

How do I use the user which is defined in the sync_function?

I don’t know the exact syntax you are looking for since we don’t have an official Javascript API, but it would be “basic” instead of “facebook” with “username” and “password”

So something like this?

var remote = {
    url : config.site.syncUrl,
    auth : {basic : {username : config.user, password: user.password}} 
  }