Skip to content

Commit

Permalink
feat: resolve .signIn() and .signOut() with .profile
Browse files Browse the repository at this point in the history
BREAKING CHANGE:

account.signIn() now has a `include` option which defaults to `account.profile`. The `include` option gets appended to `PUT /session`, so by default the sign in request is now `PUT /session?include=account.profile`, before it was just `PUT /session`
  • Loading branch information
gr2m committed Jul 25, 2016
1 parent 7e5769e commit e3355c6
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 2 deletions.
3 changes: 3 additions & 0 deletions admin/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@ function AccountAdmin (options) {
return getUsername(state)
},
signIn: function (options) {
// include defaults to account.profile, but admins have neither
options.include = ''

return signIn(state, options)

.then(function (session) {
Expand Down
20 changes: 18 additions & 2 deletions lib/sign-in.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ function signIn (state, options) {
return Promise.reject(new Error('options.username and options.password is required'))
}

if (!options.hasOwnProperty('include')) {
options.include = 'account.profile'
}

var preHooks = []
// note: the `pre:signin` & `post:signin` events are not considered public
// APIs and might change in future without notice
Expand All @@ -30,15 +34,15 @@ function signIn (state, options) {

.then(function () {
return internals.request({
url: state.url + '/session',
url: sessionUrl(state, options),
method: 'PUT',
body: internals.serialise('session', options)
})
})

.then(function (response) {
var data = internals.deserialise(response.body, {
include: 'account'
include: 'account.profile'
})

// admins don’t have an account
Expand All @@ -65,6 +69,10 @@ function signIn (state, options) {
state.account.id = data.account.id
}

if (data.account.profile) {
state.account.profile = data.account.profile
}

internals.saveAccount({
cacheKey: state.cacheKey,
account: state.account
Expand All @@ -90,3 +98,11 @@ function signIn (state, options) {
})
})
}

function sessionUrl (state, options) {
if (options.include) {
return state.url + '/session?include=' + options.include
}

return state.url + '/session'
}

0 comments on commit e3355c6

Please sign in to comment.