Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var nano = require('nano')('http://localhost:5984')
- const username = 'test'
- const userpass = '123123'
- const callback = console.log // this would normally be some callback
- const cookies = {} // store cookies, normally redis or something
- nano.auth(username, userpass, function (err, body, headers)
- {
- if (err)
- {
- return callback(err);
- }
- if (headers && headers['set-cookie'])
- {
- cookies[username] = headers['set-cookie'];
- console.log(cookies)
- }
- if (!err)
- {
- callback("success ", "it worked");
- }
- });
- { test:
- [ 'AuthSession=dGVzdDo1QTQ1RTFENDoVzjtA5v82S3bJRyI9Mz_J9dXrWA; Version=1;
- Expires=Thu, 28-Dec-2017 22:43:56 GMT; Max-Age=600; Path=/; HttpOnly' ] }
- success it worked
- name: 'Error',
- error: 'unauthorized',
- reason: 'Authentication required.',
- scope: 'couch',
- statusCode: 401,
- request:
- { method: 'POST',
- headers:
- { 'content-type': 'application/x-www-form-urlencoded; charset=utf-8',
- accept: 'application/json' },
- uri: 'http://localhost:5984/_session',
- body: 'name=test&password=123123' },
- headers:
- { 'www-authenticate': 'Basic realm="server"',
- date: 'Fri, 29 Dec 2017 06:42:10 GMT',
- 'content-type': 'application/json',
- 'cache-control': 'must-revalidate',
- statusCode: 401,
- uri: 'http://localhost:5984/_session' },
- errid: 'non_200',
- description: 'couch returned 401' }
Add Comment
Please, Sign In to add comment