CouchDB has authentication built in through it's _session API (http://wiki.apache.org/couchdb/Session_API) but I'm having trouble passing the cookie it dishes to the client through node.js
Here's my code (I'm using express.js login is the route):
exports.login = function(req, res){
var request = require('request');
var userData = {
"name":req.body.email,
"password": req.body.password
};
request.post({
'url': 'http://wamoyo.iriscouch.com/_session',
'json': userData,
}, function (error, response, body) {
if (!error && response.statusCode == 200) {
console.log(body);
}
request('http://wamoyo.iriscouch.com/_session', function (error, response, body) {
console.log(response.request.req._headers);
// Write the Cookie
res.setHeader("Set-Cookie", response.request.req._headers.cookie);
return res.render('index', { title: 'BasicChat' })
});
});
};
That doesn't seem to work, and I don't know a good way to debug this either. Any help would rock!
My fallback is the use the Jquery Couch plugin like this: (https://wamoyo.iriscouch.com/loginer/_design/Loginer/attachments%2findex.html) But there's a school of reasons why this would suck.
Also, I realize this code isn't efficient yet, I'm just trying to get it to work for now. Sorry if it's messy.
Seems like I found you again dear internet friend :)
nano
implements this, you can use it if you like:
Here is a blog post about it:
And here are is a sample (actual test code from nano)