I am using the cradle package on node to query couchdb. My node instance has admin privileges.
I am looking for the proper way to query the _users table from node.
right now, I am doing something like this:
var db = conn.database('_users');
db.exists(function (err, exists) {
if (err) {
console.log('error', err);
} else if (exists) {
db.get('org.couchdb.user:some_user', function (err, doc) {
console.log(doc);
});
} else {
console.log('database does not exists.');
}
});
Is there a cleaner way to doing this? any auth libraries similar to pouchdb-authentication?
THIS IS WHAT I DID At the time, I wasn't aware that I could just as easily use pouchdb on node. I will be using it plus pouchdb-authentication to simplify requests to to _users.
You can actually use PouchDB on top of the _users
database:
var db = new PouchDB('http://localhost:5984/_users');
db.allDocs({include_docs: true}).then(/* ... */) // <-- fetches all users
_users
is just a database. :)