Can not get correct userctx
ceremcem opened this issue · comments
When I open the example.com/_session, it returns:
{"userCtx":{"roles":["_admin","_reader","_writer"],"name":"demeter"},"ok":true,"info":{"authentication_db":"_users","authentication_handlers":["delegated","cookie","default","local"],"authenticated":"cookie"}}
But when I use the following code:
err, body, headers <- nano.auth user.name, user.password
console.log "err", err
console.log "body: "
console.log body
console.log "headers..."
console.log headers
body returns
{"roles":[],"ok":true,"name":"demeter"}
Which is not correct.
Edit
Following bash script also returns same response with nano:
#!/bin/bash
HOST=https://example.com
curl -vX POST $HOST/_session \
-H 'Content-Type:application/x-www-form-urlencoded' \
-H 'Content-Type:application/json' \
-d 'name=myuser&password=mypassword'
So the problem might not be related with nano itself, it might be a setup issue.
However, following code gets the same correct userCtx with the browser:
require! \nano
conn = nano cfg.url
err, body, headers <- conn.auth cfg.user.name, cfg.user.password
return console.log "err", err if err
if headers and headers.\set-cookie
cfg.cookie = headers.\set-cookie
else
return console.error "We got no cookie?", headers
sconn = nano do
url: cfg.url
cookie: cfg.cookie
err, session <- sconn.session
return console.error "Err: ", err if err
console.log 'Session is: ', session
This repository has been merged into apache/couchdb-nano, please continue the discussion here