Skip to content

Commit

Permalink
feat: (internal) pre:signout & post:signout events
Browse files Browse the repository at this point in the history
* * *

This commit was sponsored by Neighbourhoodie

You can hire Neighbourhoodie for all your
Hoodie / CouchDB / Offline First needs
http://go.hood.ie/thehoodiefirm
  • Loading branch information
gr2m committed Feb 22, 2016
1 parent 774b387 commit 4e319e9
Showing 1 changed file with 33 additions and 7 deletions.
40 changes: 33 additions & 7 deletions lib/sign-out.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
module.exports = signOut

var clone = require('lodash/clone')
var invokeMap = require('lodash/invokeMap')

var internals = module.exports.internals = {}
internals.request = require('../utils/request')
Expand All @@ -10,12 +11,26 @@ internals.get = require('./get')
function signOut (state) {
var accountProperties = internals.get(state)

return internals.request({
method: 'DELETE',
url: state.url + '/session',
headers: {
authorization: 'Bearer ' + state.account.session.id
}
var preHooks = []
// note: the `pre:signout` & `post:signout` events are not considered public
// APIs and might change in future without notice
// https://github.com/hoodiehq/hoodie-client-account/issues/65
state.emitter.emit('pre:signout', { hooks: preHooks })

return Promise.resolve()

.then(function () {
return Promise.all(invokeMap(preHooks, 'call'))
})

.then(function () {
return internals.request({
method: 'DELETE',
url: state.url + '/session',
headers: {
authorization: 'Bearer ' + state.account.session.id
}
})
})

.then(function () {
Expand All @@ -27,6 +42,17 @@ function signOut (state) {

delete state.account

return clone(accountProperties)
var postHooks = []

// note: the `pre:signout` & `post:signout` events are not considered public
// APIs and might change in future without notice
// https://github.com/hoodiehq/hoodie-client-account/issues/65
state.emitter.emit('post:signout', { hooks: postHooks })

return Promise.all(invokeMap(postHooks, 'call'))

.then(function () {
return clone(accountProperties)
})
})
}

0 comments on commit 4e319e9

Please sign in to comment.