Skip to content
This repository has been archived by the owner on Nov 5, 2018. It is now read-only.

Can not get correct userctx #342

Open
ceremcem opened this issue Oct 19, 2016 · 2 comments
Open

Can not get correct userctx #342

ceremcem opened this issue Oct 19, 2016 · 2 comments

Comments

@ceremcem
Copy link

ceremcem commented Oct 19, 2016

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.

@ceremcem
Copy link
Author

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 

@carlosduclos
Copy link

This repository has been merged into apache/couchdb-nano, please continue the discussion here

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants