Skip to content

Commit

Permalink
feat: options.PouchDB
Browse files Browse the repository at this point in the history
BREAKING CHANGE:

Before, `options.db` had to be passed to the Api constructor, pre-initialised with `"pouchdb-users"`:

```js
var AccountApi = require("@hoodie/account-server-api")
var PouchDB = require("pouchdb")

PouchDB.plugin(require("pouchdb-users"))

var db = new PouchDB("http://localhost:5984/_users")

db.installUsersBehavior().then(function () {
  var api = new AccountApi({
    db: db,
    secret: "secret123"
  })

  api.accounts.findAll().then(logAccountStats)
  api.accounts.on("change", logAccountChange)
})
```

Now, `options.PouchDB` is enough. Optionally `options.usersDb` for a custom users db name can be passed (it defaults to `_users`):

```js
var AccountApi = require("@hoodie/account-server-api")
var PouchDB = require("pouchdb")
  .plugin(require("pouchdb-users"))

var api = new AccountApi({
  PouchDB: PouchDB,
  usersDb: "my-users-db",
  secret: "secret123"
})
```
  • Loading branch information
gr2m committed Oct 15, 2016
1 parent d584590 commit e18d4c4
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
3 changes: 2 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,10 @@ var accountsOn = require('./lib/accounts/on')
var startListeningToAccountChanges = require('./lib/utils/start-listening-to-account-changes')

function accountApi (options) {
options.PouchDB.plugin(require('pouchdb-users'))
var accountsEmitter = new EventEmitter()
var state = {
db: options.db,
db: new options.PouchDB(options.usersDb || '_users'),
secret: options.secret,
accountsEmitter: accountsEmitter
}
Expand Down
4 changes: 4 additions & 0 deletions lib/setup.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,8 @@ function setup (state) {
throw error
}
})

.then(function () {
return state.db.installUsersBehavior()
})
}

0 comments on commit e18d4c4

Please sign in to comment.