$.couch.session returns userctx with null name

2019-07-22 16:20发布

问题:

I'm calling the following code:

$.couch.login($.extend({ name: "harry", password: "secrets"}, callback));
$.couch.session(callback);

where "harry" is just a dummy user I created using $.couch.signup and callback is a simple object specifying success/error/complete functions with bodies like these:

success: function (data) {
    console.log('Success');
    console.log(data);
}

This code returns the following:

Success
Object {ok: true, name: "harry", roles: Array[0]}

Success
Object {ok: true, userCtx: Object, info: Object}

The first return is fine, but the second, the one from session, the userCtx object is basically empty, with a null name.

Also, when I try to login using my personal username and password (the ones I use as a Futon admin), this is returned:

Success
Object {ok: true, name: null, roles: Array[1]}
(0: "_admin")

Success
Object {ok: true, userCtx: Object, info: Object}

and fascinatingly, the first request knows seems to know I'm an admin, but doesn't get any other data, and the second request does the same thing as the previous example.

Any thoughts? Am I not using $.couch.session correctly? Is there something wrong with my couch instance?

FYI I am using version 1.4.0 and built from source.

回答1:

It turns out all I really needed was an apache reverse proxy. The couch instance didn't have access to the AuthSession cookie, since it was coming from port 5984. Now things work great with the following added to my apache2.conf (may be httpd.conf for some)

LoadModule proxy_module /usr/lib/apache2/modules/mod_proxy.so
LoadModule proxy_http_module /usr/lib/apache2/modules/mod_proxy_http.so
LoadModule headers_module /usr/lib/apache2/modules/mod_headers.so

ProxyPass /_couch http://localhost:5984 nocanon
ProxyPassReverse /_couch http://localhost:5984