daleharvey/pouchdb — pull request #791 by toddbluhm (2013-06-04 09:57:39+00:00)
Title: Cors Credentials for Replication

This is an implementation of CORS Credentials for pouchdb replication. All CORS tests have been moved to the test.cors.js file. Usage is as follows (can also be found in tests).

Pouch.replicate('http://relax.com/on-the-couch', 'local-pouch', {srcWithCredentials:true, srcWithCookieAuth:{username:'admin', password:'pass'}}, function(){});

var localDB = Pouch('localdb');
localDB.replicate.from('http://relax.com/on-the-couch', {withCredentials:true, cookieAuth: {username:'admin', password:'pass'}}, function(){});

var remoteDB = Pouch('http://relax.com/on-the-couch', {withCredentials:true, cookieAuth: {username:'admin', password:'pass'}}, function(){});
remoteDB.replicate.to('localdb', function(){});

You can also just pass in pouchdb instances rather than urls/db names.

var localDB = Pouch('localdb');
var remoteDB = Pouch('http://relax.com/on-the-couch', {withCredentials:true, cookieAuth: {username:'admin', password:'pass'}}, function(){});
remoteDB.replicate.to(localDB, function(){});

Note: cookieAuth param not required (just make sure you have that auth cookie already) and variations of the above commands work too.