From 8646b932770940438ba9c5b0eda963da0f76b021 Mon Sep 17 00:00:00 2001 From: Gregor Date: Mon, 25 Jul 2016 13:37:45 -0700 Subject: [PATCH] feat: resolve .signIn() and .signOut() with .profile 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` --- admin/index.js | 3 +++ lib/sign-in.js | 20 ++++++++++++++++++-- 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/admin/index.js b/admin/index.js index 19baa9a..700eb70 100644 --- a/admin/index.js +++ b/admin/index.js @@ -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) { diff --git a/lib/sign-in.js b/lib/sign-in.js index d9816f5..7ddd35c 100644 --- a/lib/sign-in.js +++ b/lib/sign-in.js @@ -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 @@ -30,7 +34,7 @@ function signIn (state, options) { .then(function () { return internals.request({ - url: state.url + '/session', + url: sessionUrl(state, options), method: 'PUT', body: internals.serialise('session', options) }) @@ -38,7 +42,7 @@ function signIn (state, options) { .then(function (response) { var data = internals.deserialise(response.body, { - include: 'account' + include: 'account.profile' }) // admins don’t have an account @@ -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 @@ -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' +}