Reputation: 11
I am trying to authenticate a user against a CouchDB via auth header with the following code:
//Business Logic - do your stuff here.
var db = getdatabaseInstanse(localDb);
var handler = db
.replicate
.from(remoteDb, {
filter: function (doc) {
return angular.isUndefined(doc._deleted) || doc._deleted !== true;
}
});
handler
.on('complete', function (info) {
resolved({ 'Instans': db, 'Info': info, 'PouchDb': localDb, 'CouchDb': remoteDb });
})
.on('error', function (err) {
if (err.status !== 500) {
//Ignore Couch database error 500 - since it's unknown!
rejected({ 'Instans': db, 'Error': err, 'PouchDb': localDb, 'CouchDb': remoteDb });
}
});
How do I implement it in the above mentioned example. TIA
Upvotes: 1
Views: 957
Reputation: 1537
You can use the auth.username and auth.password options, as outlined in the PouchDB documentation. This would get you a db with correct authentication:
var remoteDb = new PouchDB('http://path.to/remotedb', {auth: {username: 'user', password: 'pass'}});
By the way, a simpler filter function would suffice in your case: filter: function (doc) { return !doc._deleted; }
Upvotes: 1
Reputation: 58
As I understood you need create remoteDb instance with auth options. Or place username and password in url like http://username:password@domainname
Upvotes: 0