Skip to content

Commit

Permalink
fix: Fix addUserFieldsToSession when using auth adapter.
Browse files Browse the repository at this point in the history
  • Loading branch information
SamTolmay committed Aug 3, 2022
1 parent e6261fe commit 850ee69
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 7 deletions.
15 changes: 11 additions & 4 deletions packages/api/src/routes/auth/callbacks/addUserFieldsToSession.js
Expand Up @@ -14,10 +14,17 @@
limitations under the License.
*/

function addUserFieldsToSession(context, { session, token, authConfig }) {
Object.keys(authConfig.userFields).forEach((fieldName) => {
session.user[fieldName] = token[fieldName];
});
function addUserFieldsToSession(context, { session, token, authConfig, user }) {
if (token) {
Object.keys(authConfig.userFields).forEach((fieldName) => {
session.user[fieldName] = token[fieldName];
});
}
if (user) {
Object.keys(authConfig.userFields).forEach((fieldName) => {
session.user[fieldName] = user[fieldName];
});
}
}

export default addUserFieldsToSession;
Expand Up @@ -71,9 +71,10 @@ function createSessionCallback(context, { authConfig, plugins }) {
updated_at,
...session.user,
};
if (authConfig.userFields) {
addUserFieldsToSession(context, { authConfig, session, token });
}
}

if (authConfig.userFields) {
addUserFieldsToSession(context, { authConfig, session, token, user });
}

for (const plugin of sessionCallbackPlugins) {
Expand Down

0 comments on commit 850ee69

Please sign in to comment.