CouchBase Lite to CouchDB Replication with Authentication

I am trying to develop a Cordova app by using couchbase-lite cordova plugin on the client and the Apache CouchDB on the server. I am able to create/update documents on the device and sync them with the CouchDB on server and vice -versa.
However currently there is no explicit authentication involved during these operations.
I want to create users in CouchDB and allow the CRUD and sync operations only to those users.

I am not able to understand how to add authentication credentials to the CRUD and Sync requests going from device(couchbase-lite) to the CouchDB on server.
I am using the swagger-client-min.js library as a RESt api wrapper.

This library does the following during the initialization:

var dbClient = null;
dbClient = new SwaggerClient({
spec: window.spec,
usePromise: true,
.then(function (client) {

	if (device.platform == 'Android') {
		var encodedCredentials = "Basic " + window.btoa(url.split('@')[0]);//window.btoa(url.split('/')[1].split('@')[0]);
		//var encodedCredentials = "Basic " + window.btoa("<couchdb username>:<password>"); // need something like this
		client.clientAuthorizations.add("auth", new SwaggerClient.ApiKeyAuthorization('Authorization', encodedCredentials, 'header'));
	dbClient = client;

If you notice how the basic authentication is being added here , it is nothing but the base64 encoded value of the string taken from the url itself.
When I tried to set my own couchdb admin username and password here (as shown in the commented line above), the request returns error 401 (unauthorized).

I want to know how do I acheive setting my own username password as basic authentication in this case ?
Also how to add the same for the replication?
Please let me know if someone has already tried such a scenario.

Note: I am not using CouchBase Sync Gateway and also does not intend to use it.