4

I can not pass the session correctly to CouchDB. Here is my code:

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']
        });
    }

});

But when I make a call I always get the following message:

Error: Bad DB response: {"error":"unauthorized","reason":"You are not authorized to access this db."}
Jonathan Hall
  • 75,165
  • 16
  • 143
  • 189
robert
  • 797
  • 3
  • 9
  • 23

1 Answers1

0

i tried your code and it works for me if I provide correct user credentials.

I guess the error might be in your call after this auth operation. Here is the code i tested with:

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);});;
    }

});

I suppose maybe you tried to call the nano instance instead of the db instance or sth like that?

gaugau
  • 765
  • 1
  • 9
  • 30