diff --git a/lib/get-api.js b/lib/get-api.js index 8c32430..2d7e209 100644 --- a/lib/get-api.js +++ b/lib/get-api.js @@ -17,25 +17,27 @@ function getApi (state) { } var account = mergeOptionsAndCreate(internals.Account, { url: api.url + '/account/api' }, state.account) + var CustomPouchDB = state.PouchDB.defaults({ + ajax: { + headers: { + get authorization () { + var session = api.account.get('session') + if (!session) { + return + } + + return 'Session ' + session.id + } + } + } + }) var CustomStore = internals.Store.defaults({ + PouchDB: CustomPouchDB, remoteBaseUrl: api.url + '/store/api' }) var dbName = 'user/' + account.id - var store = new CustomStore(dbName, { - ajax: function () { - var session = api.account.get('session') - if (!session) { - return - } - - return { - headers: { - authorization: 'Session ' + session.id - } - } - } - }) + var store = new CustomStore(dbName) // core modules api.account = account diff --git a/lib/get-state.js b/lib/get-state.js index 8ffc384..6ac049f 100644 --- a/lib/get-state.js +++ b/lib/get-state.js @@ -10,6 +10,11 @@ var constants = require('./constants') function getState (options) { options = options || {} + + if (typeof options.PouchDB !== 'function') { + throw new TypeError('options.PouchDB is required (see https://github.com/hoodiehq/hoodie-client#constructor)') + } + var defaultOptions = { url: getCurrentOrigin() }