我无法正确地将会话传递给CouchDB.这是我的代码: var nano = require('nano')({ 'url': 'http://myip:5984'});var conf = require('./conf');nano.auth(conf.user.name, conf.user.password, function (err, body, headers) { if (err) {
var nano = require('nano')({ 'url': 'http://myip:5984' }); var conf = require('./conf'); nano.auth(conf.user.name, conf.user.password, function (err, body, headers) { if (err) { return callback(err); } if (headers && headers['set-cookie']) { var nano = require('nano')({ 'url':'http://myip:5984', 'cookie': headers['set-cookie'] }); } });
但是当我打电话时,我总是收到以下消息:
Error: Bad DB response: {"error":"unauthorized","reason":"You are not authorized to access this db."}我尝试了你的代码,如果我提供正确的用户凭据,它对我有用.
我想这个auth操作后可能会出现错误.这是我测试的代码:
var nano = require('nano')({ 'url': 'http://localhost:5984' }); nano.auth("sara", "banana", function (err, body, headers) { if (err) { return callback(err); } if (headers && headers['set-cookie']) { console.log(headers['set-cookie']); var nano = require('nano')({ 'url':'http://localhost:5984', 'cookie': headers['set-cookie'] }) db = nano.use("userdb-73617261") db.get("_all_docs").then(function(res) { console.log(res); }).catch(function(err){console.log(err);});; } });
我想也许你试图调用nano实例而不是db实例或者那样?