I have an application using ember-couchdb-kit to interface with a CouchDB instance. I am having difficulty accessing the server after requiring authentication.

I tried cookie authentication and the cookie gets set in the browser, but it isn't sent to the database for subsequent requests according to the network dialog in both Chrome and Firefox.

I don't understand why this is happening, but in the pursuit of getting the application working, I wanted to try HTTP auth.

My document adapter is just:

App.Host = 'http://localhost:5984'
App.ApplicationAdapter = EmberCouchDBKit.DocumentAdapter.extend( { db: 'wells', host: App.Host } )

I want to add the username and password to the URL, so after the user enters them, I run:

EmberCouchDBKit.DocumentAdapter.reopen( {
  host: ( function() {
    var parts = App.Host.split( '://' )
    return "%@://%@:%@@%@".fmt( parts[0], $('#username').val(), $('#password').val(), parts[1] )
  } )()
} )

The URL for subsequent requests doesn't change though. What do I need to do?

有帮助吗?

解决方案

The adapter isn't recreated each time it's used, and reopen only applies to newly created instanes. As such you'll need to redefine it on the already existing adapter instance. Inside a route/controller you could do it like so:

var adapter = this.store.adapterFor('application');
adapter.set('host', 'foobar');
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top